如何复制表单域PdfWriter不PdfCopy在iTextSharp的表单、PdfWriter、iTextSharp、PdfCopy

由网友(初离)分享简介:我想合并两个PDF文件(仅适用于选定的页面),并添加自定义页眉和页脚他们。I would like to merge two PDF files (only selected pages) and add custom headers and footers to them.所以我不使用 PdfCopy ,简单地复...

我想合并两个PDF文件(仅适用于选定的页面),并添加自定义页眉和页脚他们。

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

所以我不使用 PdfCopy ,简单地复制页面,而不改变它。 我用的是 PdfWriter

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

现在的问题是我不知道如何复制AcroFields,Acroforms,注释和一切,除了内容与 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?

推荐答案

您想要使用 PdfWriter 类。这一切都复制到 PdfImportedPage ,你可以再使用。

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);

作为一个例子,您可以将previous code中的 OnOpenDocument 事件 PdfPageEventHelper 然后在的OnEndPage 事件时,可以使用 PdfWriter 来将整个页面的当前页面的下方。

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);