Is there any property to set fixed space between header and content of the page

Hi Support Team,

Is there any property to set fixed space between header and content of the page. Similarly, to set fixed space between footer and content of the page.

Thank you, Khurram


Thank you for contacting support.

Please note that the HeaderFooter class exposes Margin property which can be used to set space between footer and page contents. Same applies to page header. You may try using below code and enhance it further as per your requirements.

Document pdfDocument = new Document();
Aspose.Pdf.Table table = new Aspose.Pdf.Table();
table.ColumnWidths = "100";
Aspose.Pdf.Row row = new Aspose.Pdf.Row();
var row1cell1 = row.Cells.Add();
TextFragment absoluteFooterText = new TextFragment();
TextSegment footerSegment = new TextSegment("$p of $P");

Aspose.Pdf.MarginInfo margin = new Aspose.Pdf.MarginInfo();
margin.Bottom = 100;
margin.Top = 30;

for (int i = 1; i <= 100; i++)
    TextFragment textFragment = new TextFragment();
    textFragment.Text = "Aspose";
    textFragment.TextState.FontSize = 18;

foreach (Page page in pdfDocument.Pages)
    Aspose.Pdf.HeaderFooter footer = new Aspose.Pdf.HeaderFooter();
    // change this 30 to any other nymber to control the space between footer and page content
    footer.Margin = new MarginInfo(0,0,0,30);
    page.Footer = footer;
    page.PageInfo.Margin = margin;
pdfDocument.Save(dataDir + @"FooterMargin_19.9.pdf");

We hope this will be helpful if you need any further assistance.

Hi Farhan,

Thank you for your response.

You are setting a fixed page margin.Bottom = 100.
I don’t want to fix it but a dynamically inserted space between the content and footer. Because my footer content is coming from database and it could grow in height.
Please help.

Thank you, Khurram


Would you please share sample footer content which you have tried with above shared code snippet and it caused overlapping with other page content. We will test the scenario again with your footer content and address it accordingly.

This is possible, but you need to do dodgy workarounds like having the footer be part of a table, and using the getHeight of that to append the pages margins. At least, thats the only way I have found of doing similar things.


Thank you for your valuable feedback. This will certainly help other community members with similar requirements.