I have obtained and included a trial license in my code, but when using the license the file stamp does not seem to work. No errors are thrown, and some pages on some pdfs are getting the file stamps. If I remove the license initialization from the code, it stamps all pages on all pdfs as expected, and with the evaluation water mark. Am I initializing the license wrong, or is this a limitation of the trial license?
public void addHeadersAndFooters(Document pdfDoc, String enumber, String incrementedEnumber) throws Exception {
// Initialize License Instance
com.aspose.pdf.License license = new com.aspose.pdf.License();
// Set license from Stream (points to path/ file)
license.setLicense(new java.io.FileInputStream(asposeLicDir));
PdfFileStamp fileStamp = new PdfFileStamp();
// Open Document
fileStamp.bindPdf(pdfDoc);
//max of 4 items can be open in evaluation mode
//pdf doc is index 1 (for some reason?)
for (int i = 1; i < pdfDoc.getPages().size(); i++) {
//for (int i = 1; i <= 4; i++) {
try {
Page page = pdfDoc.getPages().get_Item(i);
//build and add footer
Stamp footerStamp = new Stamp ();
FormattedText footer = new FormattedText("FOR DESIGN PURPOSES ONLY NOT FOR CONSTRUCTION", java.awt.Color.BLACK, java.awt.Color.WHITE, FontStyle.Helvetica, EncodingType.Winansi, true, 10);
footerStamp.bindLogo(footer);
footerStamp.setRotation(0);
footerStamp.setOpacity(1);
footerStamp.setBackground(false);
footerStamp.setPageNumber(i);
footerStamp.setOrigin((float) ((page.getPageRect(true).getWidth() - footer.getTextWidth()) / 2), 10);
fileStamp.addStamp(footerStamp);
//build and add header
Stamp headerStamp = new Stamp ();
FormattedText header = new FormattedText("EQUIP# " + enumber, java.awt.Color.BLACK, java.awt.Color.WHITE, FontStyle.Helvetica, EncodingType.Winansi, true, 10);
headerStamp.bindLogo(header);
headerStamp.setRotation(0);
headerStamp.setOpacity(1);
headerStamp.setBackground(false);
headerStamp.setPageNumber(i);
headerStamp.setOrigin((float) (page.getPageRect(true).getWidth() - header.getTextWidth() - 20), (float) (page.getPageRect(true).getHeight() - 30));
fileStamp.addStamp(headerStamp);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
// Save updated PDF file
fileStamp.save(tempPdfPath + incrementedEnumber + ".pdf");
// Close fileStamp
fileStamp.close();
}