f1wade
f1wade

Reputation: 2967

Rotate to landscape for first page when creating PDF

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.

Upvotes: 2

Views: 2279

Answers (1)

Bruno Lowagie
Bruno Lowagie

Reputation: 77528

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.

Upvotes: 2

Related Questions