How to add page numbers in a merged pdf

Hi,

I am using Aspose.PDF.Kit for Java. I have two PDFs. PDF A has 10 pages and PDF B has 5 pages. I want to copy page number 3 and 4 from PDF B to PDF A. I am achieving this by using PdfFileEditor but the page numbers in the output PDF are still carried from the individual files.

I want the page numbers to start from 1 to 12.

Can you please suggest how can we achieve this?

Regards,

Madhura

Hi Madhura,

Thanks for using our products.

Once the PDF files are concatenated, you can add page numbers starting from 1 to 12 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();

Hi,

Thanks for your reply!

The above method is genrating the page numbers as required but it does not erase the page numbers. Is there any other method which erases the page numbers and adds new page numbers?

Regards,

Madhura

Hi Madhura,

In order to erase the existing page number information, you may consider replacing the text with blank characters. Please try using replaceText(…) method of PdfContentEditor class. Please visit the following link for further details on

Hi,

Thanks for your reply. I will try to use the class you mentioned.

Is there any method which can give me the number of pages in the pdf document?

Regards,

Madhura

Hi Madhura,


Please try using getNumberofPages(…) method of PdfFileInfo class to get the page count in a PDF document.