I am merging PDF buffers using this code at http://web.archive.org/web/20111012184438/http://alex.buayacorp.com/merge-pdf-files-with-itext-and-net.html [Mirror]
My PDFs have mixed page orientation, some are portrait and some are landscape (but all are A4)
The code does not maintain the orientation of each page and uses the orientation of the first page throughout the document. How do I go about creating a mixed orientation PDF using this code.
The trick to using multiple page sizes is to call SetPageSize()
just before calling NewPage()
. Something like this should work (I didn't compile this but it should be pretty close):
PdfImportedPage importedPage = pdfWriter.GetImportedPage(pdfReader, page);
newDocument.SetPageSize(new iTextSharp.Text.Rectangle(0.0F, 0.0F, importedPage.Width, importedPage.Height));
newDocument.NewPage();
pdfContentByte.AddTemplate(importedPage, 0, 0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With