Rotate to landscape for first page when creating PDF

耗尽温柔 提交于 2019-12-11 01:44:44

问题


I want to rotate all pages in my document to landscape

i tried:

PdfWriter.GetInstance(mydoc, New FileStream(filename, FileMode.Create))
mydoc.Open()
mydoc.SetPageSize(iTextSharp.text.PageSize.A4.Rotate())
... add rest of document and close ...

but only my 2nd page is landscape, the first is portrait.


回答1:


You need to change the page size before you open the document. The moment you invoke mydoc.Open() the first page is initialized and you can no longer change its rotation, size,...

Also: if all pages need to be rotated, why not create the document instance using the correct size and orientation from the start?

Document document = new Document(PageSize.A4.Rotate());

That way you don't have to change the size.



来源:https://stackoverflow.com/questions/17996069/rotate-to-landscape-for-first-page-when-creating-pdf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!