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

Free Support Forum - aspose.com

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

    //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.setOrigin((float) ((page.getPageRect(true).getWidth() - footer.getTextWidth()) / 2), 10);

            //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.setOrigin((float) (page.getPageRect(true).getWidth() - header.getTextWidth() - 20), (float) (page.getPageRect(true).getHeight() - 30));
        } catch (Exception e) {

    // Save updated PDF file
    fileStamp.save(tempPdfPath + incrementedEnumber + ".pdf");

    // Close fileStamp


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

        //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!


    return fileName;



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