How can I merge two PDF files and add my document text to new PDF so as to generate one long PDF file without losing annotation from existing two pdf files?
I used PDFwriter
for this but it loses the annotation, but when I used PDFSmartCopy
, it merges the PDF files (without losing the annotation) but it doesn't display document text. Here is my code:
Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);
PdfWriter wri = new PdfSmartCopy(doc, new FileStream("test.pdf"), FileMode.Create));
doc.Open();
PdfReader reader = new PdfReader(binadypdffile);
PdfContentByte content = wri.DirectContent;
doc.Add(new Paragraph("my text here on new page", FontFactory.GetFont("Arial", 12, Font.BOLD)));
int numberOfPages = reader.NumberOfPages;
for (int currentPageIndex = 1; currentPageIndex <= numberOfPages; currentPageIndex++)
{
doc.NewPage();
PdfImportedPage importedPage = wri.GetImportedPage(reader, currentPageIndex);
int pageOrientation = reader.GetPageRotation(currentPageIndex);
((PdfSmartCopy)wri).AddPage(importedPage);
}
doc.Close();