开发者

How to create single PDF document with both portrait and landscape page using iTextSharp

I have been able to create portrait pages, and landscape pages in separate documents, but now 开发者_JAVA技巧require to do this in one document. I am using ITextSharp library and the document.setpagesize seems to apply to all pages. Is this correct?

I was using PDFLib and changing page orientation was not a problem in that library.

Any suggestions? Paul.


It should only apply to pages rendered after that call.

Document doc = new Document(PageSize.WHAT_EVER);
PdfWriter writer = new PdfWriter( doc, outputStream );
doc.open();
// so long as you set the page size before add()ing anything, it should ignore the
// page sized used in the constructor.
doc.setPageSize(PageSize.LETTER); // 8.5" x 11"
// actually, I think you need to call newPage or actually add enough stuff to start a new page
// for setPageSize to take effect.  setPageSize by itself won't do the trick.
doc.add(stuffToFillALetterPageButNotStartANewOne); 

doc.setPageSize(new Rectangle(792f, 612f)); // 11" x 8.5"
doc.add(moreStuffToFillALandscapePageThusStartingANewPage);
doc.close();

The resulting PDF should have two pages. The will be 8.5x11, the other 11x8.5. Note that iText[sharp] won't generate rotated pages (8.5"x11" @ 90 degrees (or 270... shudder)). It's... sharper than that.

Dealing with rotated pages is Not Fun. At least I've never run into one that was 8.5x11 at 180 rotation in my TOO_MANY_YEARS of experience with PDF. I'd just have to fly into a murderous rage at that point. Or maybe I should generate some PDFs that way just to see who I could catch with their pants down.

[insert fiendish cackle here]

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜