开发者

Create mixed orientation PDF in iTextSharp

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开发者_如何学Go 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);


Similar to @Chris Haas. I needed page 3 to be landscape

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜