We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Page number of resultant Pdf document is not updated

Hello Everyone,

While adding two or more pdf document into one, I am not getting the updated page number of resultant pdf document. Is there any way to delete the page number? Or any other way to update the page number?

I am doing this to add two pdf document:
finalDocument.getPages().add(tempDocument.getPages())

Note: There is a way in this link for Adding and Removing page numbers using aspose.words.

Best Regards.

Hi there,


Thanks for your inquiry. You may add page number stamp with id in Pdf documents and later can delete stamp using that id as following. It will help you to remove the page number stamp from concatenated PDF document and later you can add a new page number stamp for concatenated PDF document. Hopefully it will help you to accomplish the task.


//*Adding stamp with ID//

//Open document<o:p></o:p>

Document pdfDocument = new Document(myDir + “PageNumber.pdf”);<o:p></o:p>

//Create page number stamp<o:p></o:p>

PageNumberStamp pageNumberStamp = new PageNumberStamp();<o:p></o:p>

//Whether the stamp is background<o:p></o:p>

pageNumberStamp.setBackground(false);<o:p></o:p>

pageNumberStamp.setFormat("Page # of
"
+
pdfDocument.getPages().size());
<o:p></o:p>

pageNumberStamp.setBottomMargin(10);<o:p></o:p>

pageNumberStamp.setHorizontalAlignment(HorizontalAlignment.Center);<o:p></o:p>

pageNumberStamp.setStartingNumber(1);<o:p></o:p>

//Set text properties<o:p></o:p>

pageNumberStamp.getTextState().setFont(FontRepository.findFont(“Arial”));<o:p></o:p>

pageNumberStamp.getTextState().setFontSize(14.0F);<o:p></o:p>

pageNumberStamp.getTextState().setFontStyle(FontStyles.Bold);<o:p></o:p>

pageNumberStamp.getTextState().setFontStyle(FontStyles.Italic);<o:p></o:p>

pageNumberStamp.getTextState().setForegroundColor(com.aspose.pdf.Color.getAqua());<o:p></o:p>

pageNumberStamp.setStampId(111);<o:p></o:p>

//Add stamp to particular page<o:p></o:p>

pdfDocument.getPages().get_Item(1).addStamp(pageNumberStamp);<o:p></o:p>

//Save output document<o:p></o:p>

pdfDocument.save(myDir + “output_imageStamp.pdf”);<o:p></o:p>

//Removing Stamp with id//<o:p></o:p>

PdfContentEditor contentEditor = new PdfContentEditor();<o:p></o:p>

contentEditor.bindPdf(myDir + “output_imageStamp.pdf”);<o:p></o:p>

StampInfo[] stampInfo =
contentEditor.getStamps(1);
<o:p></o:p>

//contentEditor.DeleteStampById(111);<o:p></o:p>

//Loop through each stamp<o:p></o:p>

for (int i = 0; i <
stampInfo.
length; i++)<o:p></o:p>

{<o:p></o:p>


//Check
to see if the ID = 111, if so delete the stamp.
<o:p></o:p>


if
(stampInfo[i].getStampId() == 111)
<o:p></o:p>


{ contentEditor.deleteStampById(stampInfo[i].getStampId()); }
<o:p></o:p>

}<o:p></o:p>

contentEditor.save(myDir + "output_deletedstamp.pdf");


Best Regards,

Hello Tilal Ahmad,


Thanks for your answer. But this is not what I am looking for, I am searching for deleting those page numbers, which already exists and don’t get ordered while adding two or more pdf into one. Hope you get me now.

With your suggested method, page numbers can be deleted only if they are created by PageNumberStamp.

Thanks

Hi there,


Thanks for your feedback. I am afraid there is no direct option available to remove header/footer contents added by other applications, as different applications use different logic to add header/footer. However you may try to search and replace text to remove text in PDF page footer.

Best Regards,

Hello Tilal,


My pre-existing page # was due to workbooks.

Here is the scenario: I was converting workbooks into pdf Document and then adding them into one, due to which I was getting page number from those workbook.

Solution: I disable the footer from the each sheet of the excel file, which I was using as workbook. And then I use PageNumberStamp to add the page numbers.

Thanks

Hi there,


Thanks for your feedback. It is good to know that you have manged to resolve the issue at your own.

Please keep using Aspose.Pdf and feel free to contact us for any query or concern, we will be more than happy to extend our support.

Best Regards,