我目前正在评估iTextSharp在项目中的潜在用途.我为实现目标而编写的代码是使用PDFCopy.GetImportedPage来复制现有PDF中的所有页面.我想知道的是,在复制像这样的PDF内容时,我需要注意哪些内容会从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
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
833 次 |
| 最近记录: |