Image watermark does not display on PDF

Hi,

I tried to use the ‘Add Image Watermark to PDF’ feature of Aspose PDF in my environment, following the steps described in the link below:

However, I encountered an issue where the image watermark does not appear in the original PDF.

I also attempted to add a background to a newly created PDF, and in that case, the image watermark displayed correctly. But when working with an original PDF, it seems that the API is not functioning as expected.

I am currently using the following library with a free trial:
Aspose.PDF 23.8 | Process Acrobat PDF Files via Java API

Is this problem possibly caused by the limitations of the trial version?

Thanks.

@Rich_Huang

With the trial version, you will only be able to access 4 elements of any collection of the API. However, you can remove this restriction using a 30-days free temporary license. In case issue still persists, please share your sample PDF with us so that we can test the scenario in our environment and address it accordingly.

Guiding Questions.pdf (29.7 キロバイト)
@asad.ali
Thank you for your reply. I have applied a temporary license and imported it into our environment.

I have noticed that in some cases, the image watermark displays correctly, but in others, it does not work.

I suspect that this issue may be related to the content of the PDF. I have attached an example PDF file that demonstrates the problem.

Your assistance in investigating this matter would be greatly appreciated.

Rich

@Rich_Huang

We apologize for the trouble. Would it be possible if you can please share the image as well that you are using to add the watermark?

original.img.png (49.6 キロバイト)
@asad.ali
Thanks for your reply. Please refer to the attachment.

Best regards,
Rich

@Rich_Huang

We are checking it and will get back to you shortly.

@Rich_Huang

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFJAVA-43168

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@Rich_Huang

The reason why image is not displayed - the document already has nontransparent background (white rectangle). And new background is placed after it.
So, to resolve the issue - we recommend to delete redundant rectangle (the first found rectangle is actual background) :

Document doc = new Document(dataDir + "Guiding Questions.pdf");
BackgroundArtifact background = new BackgroundArtifact();
background.setBackgroundImage(new FileInputStream(dataDir + "original.img.png"));

background.setOpacity(0.5);
background.setArtifactHorizontalAlignment(HorizontalAlignment.Center);
background.setArtifactVerticalAlignment(VerticalAlignment.Center);
background.setBackground(false);

Page item = doc.getPages().get_Item(1);
OperatorCollection contents = item.getContents();

for (Operator op : contents) {
    if (op instanceof Re) {
        contents.delete(op.getIndex());
        break;
    }
}

item.getArtifacts().add(background);
doc.save(dataDir + "watermark_23_11_fixed.pdf");

watermark_23_11_fixed.pdf (136.9 KB)