Margin in MigraDoc

Martina picture Martina · Oct 13, 2014 · Viewed 9k times · Source

I'm using MigraDoc and PDFsharp and I need to set different margins for each page in my PDF document. Using

  document.DefaultPageSetup.RightMargin = 20;
  document.DefaultPageSetup.LeftMargin = 20;

I obtain that all the pages in my document will have the same margins. How can I set the margins for each page in my document? Thank you

Answer

You should never modify DefaultPageSetup.

You can create several sections in your document. You can set the PageSetup for each section as needed.

All pages in a section will have the same page size (PageSetup). I presume you only have a single section and thus you change all pages.