Free Support Forum -

HTML Fragment Headers are not setting up Properly


Im converting the RTF files into PDF format. When adding the HTML Headers & Footers, the margins are not set properly for the Header and Footer.

Below are the process followed in this conversion

  1. Convert the Stream into RTF files
  2. Merge the RTF files into One
  3. Convert the One RTF into PDF
  4. Add the HTML Fragment Header and Footer into PDF
  5. Save the PDF

Please find the attached
File Details Follows
Source code - SourceCode.cs
Input Files - “RTF1.rtf , RTF2.rtf , HTML1.html, HTML2.html , Header.html, Footer.html”
Result Files - “\Output” + “final_output_Sample.pdf”

Issues to be Resolved

  • Header Margins are not setting properly
  • Footer Margins are not setting Properly
  • When Inserting a HTML “builder.InsertHtml”, the html added before to the existing text, But this HTML to be added in the Last.

Please help me to fix the above said issues.

Rajendran (353.7 KB)


Thank you for contacting support.

We have worked with the data shared by you and have updated your code snippet to avoid problem with margins. Please set page margins to zero before adding the header or footer on it, as in the code snippet below:

        Aspose.Pdf.Document doc = new Aspose.Pdf.Document(strPath + "\\Output\\final_output.pdf");
        // Open each page and assign Header and Footer
        foreach (Aspose.Pdf.Page page in doc.Pages)
            page.PageInfo.Margin = new MarginInfo(0, 0, 0, 0);
            page.Header = header;
            page.Footer = footer;

        // Save the PDF
        doc.Save(strPath + "\\Output\\" + "final_output.pdf", Aspose.Pdf.SaveFormat.Pdf);

Generated PDF document has been attached for your kind reference. Please feel free to contact us if you need any further assistance. final_output.pdf

3 posts were split to a new topic: How can I add the HTML text to end of the document / existing text / page