Thomas Hoevel wrote:
The PageSetup must reserve the space needed for headers and footers or they may overlap with the floating text from the main body.
To give further help on this:
- You have to set the header or foother distance, that, from what I could tell, was the distance from the top or bottom edge of the of the page.
- Then you have to set the margins, the margin should take into account both the content height of the header or footer, and the header or footer distance.
I have saved a template that supposedly gives a rough estimate of the heigth of the header or footer, by their elements.
This method doesn't work always and the code here in just a method that worked for me, just adding it here in case you need/want it.
Code:
public static int GetHeaderFooterHeight(DocumentElements headerElements)
{
double height = 0;
var docAux = new Document();
var elements = headerElements.Clone();
if (elements.Count == 0)
return 0;
docAux.LastSection.Elements = headerElements.Clone();
DocumentRenderer _renderer = new DocumentRenderer(docAux);
_renderer.PrepareDocument();
var docObjects = _renderer.GetDocumentObjectsFromPage(1);
var info = _renderer.GetRenderInfoFromPage(1);
for (int i = 0; i < docObjects.Length; ++i)
{
if (docObjects[i] is Table)
{
var tableInfo = (MigraDoc.Rendering.TableRenderInfo)info[i];
height += tableInfo.LayoutInfo.ContentArea.Height;
}
else if (docObjects[i] is Paragraph)
{
var paragraphInfo = (MigraDoc.Rendering.ParagraphRenderInfo)info[i];
height += paragraphInfo.LayoutInfo.ContentArea.Height;
}
}
return Double.IsNaN(height) ? 0 : Convert.ToInt32(height);
}
Hope it helps