PDF File Stamp Not Working With Temp License

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();
}

@alex.jones

Could you please share the source document along with the other files that are being used in the code snippet? We will test the scenario in our environment and address it accordingly.

EvaluationMode.zip (4.7 MB)
RawPDFFiles.zip (4.7 MB)
WithLicense.zip (4.7 MB)

I have attached 3 zipped folders, evaluation mode contains the function that stamps the pdfs as well as the output pdfs from that version. WithLicense contains the function with the license included as well as the pdf output from that version. RawPDFFiles contains the pdf files unmodified. Below is the base function where the pdf files are passed to the stamping function.

public String downloadCutsheets(Project project, String reportLink) throws Exception {
String filePath = “C:\”;
String fileName = filePath + “AnotatedPDFs\output\PDFs.zip”;
File newFile = new File(fileName);
FileOutputStream zipFile = new FileOutputStream(newFile);
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(zipFile, 64000);
ZipOutputStream output = new ZipOutputStream(bufferedOutputStream);
String[] fileNames = {“DCS01”, “GLV01”, “IRD01”, “RCK01”, “STP01”};

    for (String s : fileNames) {
        String pdfFile = filePath + "AnotatedPDFs\\RawPDFFiles\\" + s + ".pdf";
        File f = new File(pdfFile);
        ZipEntry zipEntry = new ZipEntry(pdfFile);
        output.putNextEntry(zipEntry);

        //start size modification
        Document pdfDoc = new Document(filePath + "AnotatedPDFs\\RawPDFFiles\\" + f.getName());
        this.addHeadersAndFooters(pdfDoc, s, s);
        File modifiedCutsheet = new File(filePath + "AnotatedPDFs\\output\\temp\\" + s + ".pdf");
        FileInputStream finalFile = new FileInputStream(filePath + "AnotatedPDFs\\output\\temp\\" + s + ".pdf");

        IOUtils.copy(finalFile, output);  // this method belongs to apache IO Commons lib!

        finalFile.close();
        output.closeEntry();
        modifiedCutsheet.delete();
    }

    output.finish();
    output.close();
    return fileName;

}

@alex.jones

We have tested the scenario using Aspose.PDF for Java 22.5 version with valid license and were unable to notice any issues. Please check the attached output documents generated at our end:

stampedDocuments.zip (4.7 MB)

Also, we only changed one line in the code snippet like below:

// iterate through all pages
for (int i = 1; i <= pdfDoc.getPages().size(); i++) {
 // stamping code
}