Margin in MigraDoc
Asked Answered
S

1

10

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

Sabinasabine answered 13/10, 2014 at 9:39 Comment(0)
O
14

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.

Oireachtas answered 13/10, 2014 at 9:52 Comment(4)
It works. I made the mistake of believing that I could set "document.DefaultPageSetup.RightMargin = 20;" to set all the pages of the document and than overwrite a specific page using "sixthPage.PageSetup.RightMargin = 0;". Thank you for your help.Sabinasabine
Nice to hear it works. When you create a MigraDoc document, then there are sections and paragraphs, but no pages. Pages are created when you render to PDF. I'm not sure what you need, but MigraDoc allows settings different margins for even and odd pages to support double-sided printing; additionally you can set different margins for the first page of a section. Another approach that could work: set the smallest margin for all pages and set larger margins for some paragraph formats. This allows mixing different margins on one page - just add page breaks if that is not desired.Oireachtas
The last two sentences dissolve my doubts. I used different margins to put some tables and images in the position that I needed in the page. I'm not able to put a table or an image in a certain position on a page so I'm solving the problem by playing with the margins.Sabinasabine
You can set table.Rows.LeftIndent to indent tables. There are many options to position images on the page (relative or absolute), so IMHO no need to play with page margins to achieve this.Oireachtas

© 2022 - 2024 — McMap. All rights reserved.