empira / PDFsharp

PDFsharp and MigraDoc Foundation for .NET 6 and .NET Framework
https://docs.pdfsharp.net/
Other
398 stars 91 forks source link

MigraDoc: Support different margins for first page in PageSetup #120

Closed helluvamatt closed 1 month ago

helluvamatt commented 1 month ago

I have a need for both top and bottom margins to be different on the first page than those on subsequent pages, because I have both a header and footer for an invoice PDF that is drastically different on the first page. (For reference, I have default top/bottom margins of 3/4" to support a single line of text on the header and footer, but the first page needs to have top/bottom margins of 2.5" and 3" respectively.

I found this forum post from 2014 where a forum member figured out the beginnings of a solution: https://forum.pdfsharp.net/viewtopic.php?t=2835

Alternatively, if there was a way for the "content area" of each page to not overlap the header or footer or respect the measured size of the header/footer for that page.

If the authors have any suggestions, I would love to hear. If not, I would be interested in beginning work on a PR based on the above linked forum post. I've confirmed the FormattedDocument still contains a few methods for measuring the Header/Footer and determining content area.

ThomasHoevel commented 1 month ago

It is easy to add some whitespace at the start of the document to prevent overlapping of body and header. It is possible to add a pagebreak to prevent overlapping of body and footer, but depending on your contents, this could be simple or complicated.

helluvamatt commented 1 month ago

My specific use-case would probably be better served by drawing the first summary page directly with PDFsharp, then using MigraDoc to render the rest of the invoice and combining the two PdfDocument instances before returning the final PDF to the user.

Thanks for your input!

ThomasHoevel commented 1 month ago

Margins are set per section. Another solution could be using two sections: one section for the first page with large margins at top and bottom, one section for the rest.

You can still use PDFsharp to draw certain elements on the first page.