Can't add footer to existing PDF

Hi,

We have a license for Aspose Cells and are considering a purchase of Aspose PDF for another business need. We currently use Aspose Cells to save an Excel workbook with many sheets as a PDF, and we need to be able to add page numbers to the PDF after the fact.

So the business need that we want aspose PDF to solve is modifying pre-existing PDF's.

The theory was to use the Aspose PDF api to append a footer with a page number to each page in the PDF file.

This does not appear to work. After the code to add footers executes, the "Pdf.save()" method throws an exception about "direct-to-file". So, I then used a sample from the Aspose website that uses the Pdf.close() method as recommended. This does not appear to save anything to the file, though.

I attached a PDF file we created with Aspose Cells and are trying to add page numbers for. The following is the code being used to add footers:

Pdf pdf = new Pdf(new BinaryFileStream("C:\\WIP\\combined.pdf"));
Section sec1 = pdf.getSections().add();

HeaderFooter footer = new HeaderFooter(sec1);
sec1.setOddFooter(footer);
sec1.setEvenFooter(footer);
Text footerText = new Text(footer, "some footer text");
footer.getParagraphs().add(footerText);

pdf.close();

Am I incorrectly initializing the existing PDF? Or am I just not able to add footers to a pre-existing PDF file when using Aspose PDF for Java?




Hi Vinny,

Thanks for using our products.

The code snippet which you are using to add Footer to the PDF document is actually for the creation of PDF documents from scratch and Aspose.Pdf for Java is a component which provides the capability to create PDF documents from scratch in Java environment. Whereas we have a product named Aspose.Pdf.Kit for Java which provides the capability to manipulate/edit existing PDF documents and in order to add page number information in existing PDF document, please try using addPageNumber(FormattedText formattedText, float x, float y) method of PdfFileStamp class. In case you still face the same problem or you have any further query, please feel free to contact. We are sorry for your inconvenience.