Free Support Forum - aspose.com

How to add pagnumber in the footer of a PDF

Hi ,

Could you kindly let me know how to add the current page number in the footer of the PDF.

I am already using PDFFileStamp to add the file name of the PDF in the footer,I want to display the Page number near to this file name like below.

for first page:

Gen Corr - Report of Latest Progress on Matter - Page 1 of 17

and for the last page:

Gen Corr - Report of Latest Progress on Matter - Page 17 of 17

Thank you

Anand

Hi Anand,


Thanks for your inquiry. You can easily achieve your requirement by using replaceable symbols. Please check following documentation link for details and code snippet. Hopefully it will serve the purpose.


Please feel free to contact us for any further assistance.

Best Regards,

Hi Anand,


Tilal shared the information on how to add PageNumber information while creating a new PDF file using Aspose.Pdf for Java. However if you need to add PageNumber information in existing PDF file, please try using addPageNumber(…) method of PdfFileStamp class.

[Java]

String path = “./examples/resources/”;<o:p></o:p>

String inFile = path + "example2.pdf";

String outFile = path + "example2withpagenumber.pdf";

PdfFileStamp fileStamp = new PdfFileStamp(inFile, outFile);

//add page number

FormattedText ft = new FormattedText("Page # .", new Color(0, 0, 100),

FontStyle.CourierBold, EncodingType.Winansi, false, 10);

fileStamp.addPageNumber(ft);

fileStamp.close();