0

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Dan
  • 5,692
  • 3
  • 35
  • 66

1 Answers1

1

I got this working using the method I mentioned in my question, except that for the first pass, I rendered the header content into the body instead of the header area. That meant that the DocumentRenderer.GetRenderInfoFromPage() then worked. This pass was only used to calculate the header content height anyway. Then for the 2nd pass, it renders the header content into the header as usual.

Dan
  • 5,692
  • 3
  • 35
  • 66