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

Free Support Forum - aspose.com

Why am I getting an error while adding an Image Artifact to PDF pages?


I am trying to add a WatermarkArtifact to pages in a PDF document, but I get this error:
Exception in thread "main" class com.aspose.pdf.internal.ms.System.lh: Invalid image stream (stream)

Note that I am not using an image stream.

For reference, here is my code:

com.aspose.pdf.Document doc = new com.aspose.pdf.Document(fileName);
WatermarkArtifact artifact = new WatermarkArtifact();
for (Page page : doc.getPages()) {


We can not reproduce the issue with latest version of the API while using your code. Moreover, you can also try to add an image watermark as explained at Add Image stamps in PDF programmatically with Java.

I was using version 19.1, but since you mentioned that the problem does not exist in the latest release, I downloaded and used 21.6 to test it with, and still got the same error.

I am aware of the ImageStamp method, but WatermarkArtifact makes more logical sense to use for applying watermarks to documents, so I am trying to use it instead.

For clarification, the error fires when page.getArtifacts().add(artifact); is being executed.


We can not still reproduce the exception on our end. Can you please share a sample application for reproducing it. However, there is no difference in both approaches as same output can be created as per your requirements.