Reputation: 963
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?
Upvotes: 3
Views: 3547
Reputation: 2113
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);
Upvotes: 2