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
}
}