Adding a stamp as an artifact in a pdf


I need to add an image stamp on an existing pdf, and this image needs to pass accessibility requirements.

If I understand correctly I need to use an artifact to achieve this. There was a similar question on the forum before- Marking TextStamp as Artifact, in which you suggested using an WatermarkArtifact.

However the WatermarkArtifact code throws a null exception, (WatermarkArtifact’s content and Rectangle properties also throw a null exception, not sure if that’s relevant)

I simply cannot find any example online to make this work- an image stamp/watermark/whatever that passes PDF/UA.

Here is my code. the last line throws the exception.

        Document pdfDocument = new Document(filePath);
        Artifact watermark = new WatermarkArtifact();

        FileStream file = new FileStream(imagePath , FileMode.Open);

        watermark.Position = new Aspose.Pdf.Point(x, y);
        watermark.Text = "Accessible";
        watermark.IsBackground = true;
        watermark.ArtifactHorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
        watermark.ArtifactVerticalAlignment = Aspose.Pdf.VerticalAlignment.Center;

        pdfDocument.Pages[1].Artifacts.Add(watermark); - this throws a null exception

Any idea? Thank you!


Could you please also share the same sample source file that you have been using with this code snippet? We will test the scenario in our environment and address it accordingly.

Hi Asad

It happens with any pdf. Attached is an example of an empty pdf where it happens too:
filePath= empty.pdf (25.1 KB)

The image I try to add as watermark:
imagePath= image.png (8.4 KB)

The full stack trace of the exception:

message: Object reference not set to an instance of an object.

exception: Aspose.PDF at Aspose.Pdf.WatermarkArtifact.#=z2GbaF5H4seFt(XForm #=z1DxWpRU=)
at Aspose.Pdf.Artifact.#=zib$gB4w=()
at Aspose.Pdf.Artifact.#=z0O9RRXg=()
at Aspose.Pdf.Artifact.#=zlTJiYQE=()
at Aspose.Pdf.Artifact.#=zqklywGgEiqP0(OperatorCollection #=z1t$sL_o=)
at Aspose.Pdf.ArtifactCollection.Add(Artifact artifact)


This needs to be investigated in details. Therefore, a ticket as PDFNET-53169 has been logged in our issue tracking system. We will further look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.


Are there any news about this? I just need to know what causes the exception.


Regretfully, the ticket has not been yet investigated. The issue was logged under free support model and it will be analyzed on a first come first serve basis. We will surely inform you once the ticket is fully analyzed and we have determined the cause behind this exception. Please be patient and spare us some time.

We are sorry for the inconvenience.