2014-03-13 93 views
1

我目前正在評估iTextSharp在項目中的潛在用途。我爲實現目標而編寫的代碼使用PDFCopy.GetImportedPage來複制現有PDF中的所有頁面。我想知道的是,在複製這樣的PDF內容時,我需要知道的所有內容都將從PDF和/或頁面中丟失?例如,我已經注意到的一件事是我需要手動將任何書籤和命名目的地添加到我的新PDF中。iTextSharp:從其他PDF複製PDF內容時丟失了什麼?

下面是一些粗糙的示例代碼:

 using (PdfReader reader = new PdfReader(inputFilename)) 
     { 
      using (MemoryStream ms = new MemoryStream()) 
      { 
       using (Document document = new Document()) 
       { 
        using (PdfCopy copy = new PdfCopy(document, ms)) 
        { 
         document.Open(); 

         int n; 
         n = reader.NumberOfPages; 
         for (int page = 0; page < n;) 
         { 
          copy.AddPage(copy.GetImportedPage(reader, ++page)); 
         } 

         // add content and make further modifications here 
        } 
       } 

       // write the content to disk 
      } 
     } 

回答

5

基本上任何的文檔級別,而不是網頁級別會迷路和兩個書籤和目的地是文件級。拉起PDF spec並查看3.6.1節中文檔目錄中的其他條目,包括線索,打開和附加動作以及元數據。

您可能已經看到了這些,但這裏有一些如何merge Named Destinations以及如何merge Bookmarks的示例(Java)。