jao
jao

Reputation: 18610

How do I change the margin for the second page in a PDF using iTextsharp?

Is there a way to change the page margins for the second page in a PDF using iTextSharp?

I now have:

Document document = new Document(PageSize.A4, 144f, 72f, 144f, 90f);

PdfWriter.GetInstance(document, ms);

/* first page content */

document.NewPage();
document.SetMargins(72f, 72f, 72f, 100f);

/* second page content */

However, the margins on the second page are the ones set for the first page.

Upvotes: 5

Views: 8188

Answers (1)

Bruno Lowagie
Bruno Lowagie

Reputation: 77528

Switch the two lines:

document.SetMargins(72f, 72f, 72f, 100f);
document.NewPage();

As documented, the NewPage() function performs a lot of initialisations, among others, setting the margins. So you need to change the margins BEFORE triggering a new page, not after.

Upvotes: 16

Related Questions