How to add footers to all pages except last within a section

Hello,


I’m using Pdf.Generator to build a PDF document. Within one section, I need to add a “Continued on next page” footer. So, needs to be on every page in the section except the last.

I’m having trouble figuring out a way to do this. Any ideas?

Thanks!

Thanks for contacting support.

Lifo:
I’m using Pdf.Generator to build a PDF document.

I am afraid the Aspose.Pdf.Generator is going to be obsolete soon and it is strongly recommended to use new Document Object Model (DOM). In new DOM approach you have been provided more access to all elements of the PDF Document. Furthermore you may visit “Introduction to DOM API” in our API documentation.

Lifo:
Within one section, I need to add a “Continued on next page” footer. So, needs to be on every page in the section except the last.

Please check the following code snippet in which I have added footer into each page of the Document except the last one. I have also attached the generated output document for your reference.

Document pdfDocument = new Document(dataDir + “SampleForFooter.pdf”);

HeaderFooter footer = new HeaderFooter();

TextFragment text = new TextFragment("Continued on next page...");

text.TextState.HorizontalAlignment = HorizontalAlignment.Right;

footer.Paragraphs.Add(text);

for(int i = 1; i< pdfDocument.Pages.Count; i++)

{

pdfDocument.Pages[i].Footer = footer;

}

pdfDocument.Save(dataDir + "SampleForFooter_out.pdf");

Moreover you may also check “Manage Header and Footer in a PDF file” section in our API documentation. In case if you need any further assistance please feel free to let us know.

Best Regards,

This is helpful, however, I need to add it within a section. Not to the entire document. Is there any way to do that?


Thank you.

Hi There,


Thanks for contacting support.

Please note that the Sections in old Aspose.Pdf.Generator approach has been replaced with Pages in new DOM model. However to understand your requirements more precisely we need a sample output document. We will really appreciate if you please share a sample output document so that we can share some information accordingly.


Best Regards,

Hi,


Adding more to Asad’s reply, the Aspose.Pdf.Generator.Section represents individual page inside PDF document and in new Document Object Model of Aspose.Pdf namespace, Aspose.Pdf.Page represents a specific page inside PDF document.

I am unclear on how to use the DOM model to build a document from scratch.


Do I have to deal with the pagination myself? I see Document.Pages.Add() ?

I did not see any examples of this in the documentation. Could you please point me in the right direction?

Thanks.

Hi,


You can create as well as manipulate existing PDF file using new Document Object Model. So in order to create a document from scratch, please try instantiating Document object without any argument and then add pages to PageCollection of PDF file.

For further information, please visit Working with Aspose.Pdf