Create a mixed PDF orientation in iTextSharp

I am combining PDF buffers using this code http://web.archive.org/web/20111012184438/http://alex.buayacorp.com/merge-pdf-files-with-itext-and-net.html [Mirror ]

My PDF files have a mixed page orientation, some of them are portrait and some are landscape (but they are all A4)

The code does not support the orientation of each page and uses the orientation of the first page in the document. How do I create a mixed-orientation PDF using this code.

+4
source share
2 answers

The trick to using multiple page sizes is to call SetPageSize() just before calling NewPage() . Something like this should work (I did not compile this, but 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); 
+7
source

Looks like @Chris Haas. I need page 3 for the landscape.

  if (PageNumber == 3) { pDoc.SetPageSize(new iTextSharp.text.Rectangle(0,0,PageSize.LETTER.Height,PageSize.LETTER.Width)); } pDoc.NewPage(); 
0
source

Source: https://habr.com/ru/post/1343321/


All Articles