Main content is getting overlapped with header

Hi all,

I’m using Aspose.PDF for converting HTML content to PDF by adding header and footer for all pages, but on converting header and main content are getting overlapped(attaching Snapshot). Adding code for reference. If anyone knows please help.

image.png (45.7 KB)

Code Snippet:

 Aspose.Pdf.HtmlFragment htmlFragment;
                Aspose.Pdf.Page page = doc.Pages.Add();
                //page.SetPageSize(FPageWidth * InchToPointsFactor, FPageHeight * InchToPointsFactor); //convert from inches to points
                
                if (!string.IsNullOrEmpty(header))
                {
                    page.Header = new Aspose.Pdf.HeaderFooter();
                    page.Header.Paragraphs.Add(new Aspose.Pdf.HtmlFragment(header));
                    page.Header.IsClipExtraContent = false;
                }

                htmlFragment = new Aspose.Pdf.HtmlFragment(mainContent);
                page.Paragraphs.Add(htmlFragment);

                if (!string.IsNullOrEmpty(footer))
                {
                    page.Footer = new Aspose.Pdf.HeaderFooter();
                    page.Footer.Paragraphs.Add(new Aspose.Pdf.HtmlFragment(footer));
                    page.Footer.IsClipExtraContent = false;
                }

HTML Data:

<p class="PlaygroundEditorTheme__paragraph" dir="ltr"><div  style=" width: 100%;">

    <div type="header"  style="color: #666666;">

        <p class="HeaderEditorTheme__paragraph" dir="ltr">

            <p class="HeaderEditorTheme__paragraph"><br></p>

            <p class="HeaderEditorTheme__paragraph" dir="ltr"><span>HEader Content</span></p>

            <p class="HeaderEditorTheme__paragraph" dir="ltr"><span>HEader Content</span></p>

            <p class="HeaderEditorTheme__paragraph" dir="ltr"><span>HEader Content</span></p>

            <p class="HeaderEditorTheme__paragraph" dir="ltr"><span>HEader Content</span></p>

            <p class="HeaderEditorTheme__paragraph" dir="ltr"><span>HEader Content</span></p>

            <p class="HeaderEditorTheme__paragraph" dir="ltr"><span>HEader Content</span></p>

            <p class="HeaderEditorTheme__paragraph" dir="ltr"><span>HEader Content</span></p>

            <p class="HeaderEditorTheme__paragraph" dir="ltr"><span>HEader Content</span></p>

            <p class="HeaderEditorTheme__paragraph" dir="ltr"><span>HEader Content</span></p>

            <p class="HeaderEditorTheme__paragraph" dir="ltr"><span>HEader Content</span></p>

            <p class="HeaderEditorTheme__paragraph" dir="ltr"><span>HEader Content</span></p>

            <p class="HeaderEditorTheme__paragraph" dir="ltr"><span>HEader Content</span></p>

            <p class="HeaderEditorTheme__paragraph" dir="ltr"><span>HEader Content</span></p>

            <p class="HeaderEditorTheme__paragraph" dir="ltr"><span>HEader Content</span></p>

            <p class="HeaderEditorTheme__paragraph" dir="ltr"><span>HEader Content</span></p>

            <p class="HeaderEditorTheme__paragraph" dir="ltr"><span>HEader Content</span></p>

            <p class="HeaderEditorTheme__paragraph" dir="ltr"><span>HEader Content</span></p>

            <p class="HeaderEditorTheme__paragraph" dir="ltr"><span>HEader Content</span></p>

            <p class="HeaderEditorTheme__paragraph" dir="ltr"><span>HEader Content</span></p>

            <p class="HeaderEditorTheme__paragraph" dir="ltr"><span>HEader Content</span></p>

            <p class="HeaderEditorTheme__paragraph" dir="ltr"><span>HEader Content</span></p>

            <p class="HeaderEditorTheme__paragraph"><br></p>

        </p>

    </div>#$HE</div><div><p class="PlaygroundEditorTheme__paragraph"></p>

            <p class="PlaygroundEditorTheme__paragraph" dir="ltr"><span>Test content</span></p><p class="PlaygroundEditorTheme__paragraph"><div type="bookmark" code="signature" id="10" display="Signature" displaydata="N/A" qrlink="undefined" studysignpermission="true" signature="" isvalidfinalreport="true" fullname="Satwik K" istemplateview="undefined" style="display: table; text-align: center;"><h3>Electronically signed by Satwik K at 5/12/2023, 1:43:48 PM</h3></div></p><p class="PlaygroundEditorTheme__paragraph" dir="ltr"><br></p><p class="PlaygroundEditorTheme__paragraph"><br></p></p></div>

Thanks
Satwik

@Satwikk8

In order to avoid overlapping, you need to specify appropriate margins for HtmlLoadOptions so that HTML Content can spare some space for the header and footer.

HtmlLoadOptions htmlOptions = new HtmlLoadOptions();

htmlOptions.PageInfo.Margin.Left = 72;
htmlOptions.PageInfo.Margin.Right = 72;
htmlOptions.PageInfo.Margin.Top = 72; // depending upon how long your header is
htmlOptions.PageInfo.Margin.Bottom = 72; // depends upon the footer height