How to copy form fields with PdfWriter not PdfCopy in iTextSharp

白昼怎懂夜的黑 提交于 2019-12-12 15:22:52

问题


I would like to merge two PDF files (only selected pages) and add custom headers and footers to them.

Therefore I do not use PdfCopy that simply copies the page without altering it. I use the PdfWriter.

The problem is I do not know how to copy AcroFields, Acroforms, Annotations and everything else except content with the PdfWriter.

Do you know how to do this?


回答1:


You want to use the GetImportedPage method of the PdfWriter class. This copies everything into a PdfImportedPage that you can then use.

PdfReader pdfReader = new PdfReader(originalFile);
PdfImportedPage importedPage = pdfWriter.GetImportedPage(pdfReader, pageNumber);

As an example, you can place the previous code in the OnOpenDocument event of a PdfPageEventHelper and then in the OnEndPage event you can use the DirectContentUnder object of the PdfWriter to place the entire page underneath your current page.

pdfWriter.DirectContentUnder.AddTemplate(importedPage, 0, 0);


来源:https://stackoverflow.com/questions/10881782/how-to-copy-form-fields-with-pdfwriter-not-pdfcopy-in-itextsharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!