We're using Migradoc to generate PDFs which contain headers sections so that the headers are displayed on each page.
The height of the content in the header can vary though. I'm setting the position of the body content using document.DefaultPageSetup.TopMargin
. However, this is currently a fixed 'best guess' value. Sometimes the content is bigger, causing an overlap.
I need a way to calculate the height of the header, so that I can set the document.DefaultPageSetup.TopMargin
value appropriately.
I'm assuming for this, I'll have to do it in two passes - eg. generate the PDF, inspect the rendered header height, then generate the PDF again setting the document.DefaultPageSetup.TopMargin
.
I can't see a way of inspecting the height of the header once I've rendered the PDF the first time though. I notice there's a method called GetRenderInfoFromPage()
in the DocumentRenderer
. This looks like what I want, except that it doesn't seem to include the header data. If in the first PDF generation, I just render the header on the first page and no content, then GetRenderInfoFromPage(1)
returns an empty array. If I call it on any other page other than 1, it returns null
.
We're also using PdfSharp
as a final pass to add a water mark. So potentially if I can query the header height using this - that might also work? I can't find a way of doing this either though.
Does anyone know if it's possible to query the rendered header height?