Free Support Forum - aspose.com

Header and Footer "moving" further down page on each page and page number resetting

Hello,

I am creating a header object like so:

Aspose.Pdf.Text.TextState tsNormal = new Aspose.Pdf.Text.TextState() { FontSize = 8F, HorizontalAlignment = HorizontalAlignment.Right };

Aspose.Pdf.Table headerTable = new Aspose.Pdf.Table();
            headerTable.ColumnWidths = string.Format("{0} {1}", 228, 228);
            Aspose.Pdf.Row headRowOne = headerTable.Rows.Add();
            Aspose.Pdf.Row headRowTwo = headerTable.Rows.Add();

            headRowOne.Cells.Add("", tsNormal);
            headRowOne.Cells.Add("", tsNormal);
            headRowTwo.Cells.Add(string.Format("Engagement Name: {0}\r\nLodgement ID: {1}", EngagementName, lodgeId), tsNormal);
            headRowTwo.Cells.Add(string.Format("Generated on {0}\r\nGenerated by {1}", DateTime.Now.ToShortDateString(), Context.User.Identity.Name), tsNormal);

        Aspose.Pdf.HeaderFooter headerPortrait = new Aspose.Pdf.HeaderFooter();
        headerPortrait.Paragraphs.Add(headerTable);

I create a footer in a similar way but with the “$p” token to refer to the page number

I create pages in a separate routine where I pass in the header and footer objects. These pages have tables which sometimes split across a few pages.

protected Aspose.Pdf.Page GenerateSectionStatementInfo(Aspose.Pdf.Document doc, Aspose.Pdf.HeaderFooter header, Aspose.Pdf.HeaderFooter footer)
{
Aspose.Pdf.Page pg = doc.Pages.Add();
            pg.Header = header;
            pg.Footer = footer;
...

return pg;
}

The document is created successfully but the header and footer appears about 10 points lower on each page, after a few pages the footer disappears off the bottom of the page and the header is over the top of the page content.

Also, on each new Page object the page number goes back to “2” but then on the next page the correct number is reported until the first page of a new Page object starts. So across all my footers I get [2,3,4,5,6,7][2,9,10][2,12,13][2,15,16][2,18] (where […] represents one Page object).

Any help would be much appreciated.

Many thanks,

@gordon.davies

Thanks for contacting support.

I have tested the scenario with Aspose.Pdf for .NET 17.8, while using following code snippet and observed that headers and footers kept shifting their original position with interval of 10 points. Furthermore, I have also observed that page numbers were not showing correctly in the resultant PDF document.

Document doc = new Document();

Aspose.Pdf.Text.TextState tsNormal = new Aspose.Pdf.Text.TextState() { FontSize = 8F, HorizontalAlignment = HorizontalAlignment.Right };

Aspose.Pdf.Table headerTable = new Aspose.Pdf.Table();
headerTable.ColumnWidths = string.Format("{0} {1}", 228, 228);
Aspose.Pdf.Row headRowOne = headerTable.Rows.Add();
Aspose.Pdf.Row headRowTwo = headerTable.Rows.Add();

headRowOne.Cells.Add("", tsNormal);
headRowOne.Cells.Add("", tsNormal);
headRowTwo.Cells.Add(string.Format("Engagement Name: {0}\r\nLodgement ID: {1}", "Jane Doe", "12345"), tsNormal);
headRowTwo.Cells.Add(string.Format("Generated on {0}\r\nGenerated by {1}", DateTime.Now.ToShortDateString(), "Aspose.Pdf for .NET 17.8"), tsNormal);

Aspose.Pdf.HeaderFooter headerPortrait = new Aspose.Pdf.HeaderFooter();
headerPortrait.Paragraphs.Add(headerTable);
            
Aspose.Pdf.HeaderFooter footerPortrait = new Aspose.Pdf.HeaderFooter();
footerPortrait.Paragraphs.Add(new TextFragment("$p"));

Page currpage = doc.Pages.Add();
currpage.Header = headerPortrait;
currpage.Footer = footerPortrait;

for (int i = 0; i < 100; i++)
{
 currpage.Paragraphs.Add(new TextFragment("Aspose.Pdf for .NET 17.8"));
}

for (int i = 0; i < 20; i++)
{
 Page page = doc.Pages.Add();
 page.Header = headerPortrait;
 page.Footer = footerPortrait;
}

doc.Save(dataDir + "HeaderFooter_out.pdf"); 

Please note that, above mentioned both issues were not noticed on those pages which were automatically added by the API due to lengthy content. For your reference, I have attached an output document, generated by above code snippet.

HeaderFooter_out.pdf (17.3 KB)

Now concerning to the issues, we have logged them with following IDs in our issue tracking system.

  • PDFNET-43172 (Header and Footer keep shifting at lower position on subsequent pages)
  • PDFNET-43173 (Page Number in the footer are not showing correctly)

We will further look into the details of these issues and keep you posted with the status of their correction. Please be patient and spare us little time.

We are sorry for the inconvenience.

Hello,

Are there any updates around the likelihood of a potential fix / workaround and timing?
We are looking to release a new version of our software shortly and would very much like to incorporate if available.

Thankyou

@gordon.davies,
Both the linked ticket IDs PDFNET-43172 and PDFNET-43173 are pending for the analysis and not resolved yet. Our product team will investigate as per the development schedules. We will let you know once a significant progress has been made in this regard.

I was able to resolve this issue by calling the “.Clone()” method on the HeaderFooter object for each page where I used it.

@rwdazey

Thanks for your feedback.

It is good to know that your issue has been resolved. Please keep using our API and in case of any assistance, please feel free to let us know.