Hello we have been moving from old aspose.pdf to com.aspose.pdf.document
we have a typical PDF generation where there is a header and footer with some informaiton
footer will have something like page # of # and plus some other text.
I am able to add textstamp on page 1 it’s all good
But when I add table it will automatically add as many pages as required in PDF.
How can I get the header and footer on all the pages ?
Hi Ritesh,
Thanks for your inquriy. Please use following code snippet to set Header/Footer while creating a new PDF document, it will help you to accomplish the task.
Document pdf = new Document();<o:p></o:p>
com.aspose.pdf.Page page =
pdf.getPages().add();
com.aspose.pdf.HeaderFooter footer = new
com.aspose.pdf.HeaderFooter();
TextFragment ftext=new TextFragment("Page $p /
$P");
ftext.getTextState().setHorizontalAlignment(com.aspose.pdf.HorizontalAlignment.Center);
footer.getParagraphs().add(ftext);
page.setFooter(footer);
TextFragment text = new TextFragment("Hello
World");
for (int i = 0; i < 400;
i++)
{
page.getParagraphs().add(text);
}
pdf.save("E:/data/Headerfooter_DOM.pdf");
Please feel free to contact us for any further assistance.
Best Regards,