Is it safe to reuse the PdfImage in multiple PDF pages?

I am adding a watermark in multiple pages

        var watermark = PdfImage.Load("file");
        watermark.Size = new PdfSize(width, height);
        page1.Content.DrawImage(watermark, new PdfPoint(X,Y));
        page2.Content.DrawImage(watermark, new PdfPoint(X,Y));
        page3.Content.DrawImage(watermark, new PdfPoint(X,Y));

Is it OK to Draw that same image in multiple pages like this?

Hi,

Yes, you should be able to draw the same PdfImage multiple times, on the same and on a different page.
Also, you should be able to draw it even on a different PdfDocument.

Regards,
Mario

Hi Mario. Sometimes after a change in the way we print the PDF (Not only the code I quoted above) I irregularly faced an Exception saying that
“Basic PDF object contains descendant indirect object that is contained in another PDF document”

Can you help me to understand better what does this mean and what is often the cause of it? From a quick research, I understand that it should only happens if there are multiple PdfDocument being handled at once / using the same resource.

Can you please try again with the latest bugfix version:
https://www.gemboxsoftware.com/pdf/nightlybuilds/GBA17v1309.zip

Or the latest NuGet package:
Install-Package GemBox.Pdf -Version 17.0.1309-hotfix

If the problem remains, can you please send us a small Visual Studio project that reproduces the issue so that we can investigate it?

Thanks, Mario. I will just wait and see beacuse this happens irregularly I didn’t have the chance to capture a stacktrace
If this surface again I will switch to the hotfix. Right now it is not possible for me to do so

System.ArgumentException: Basic PDF object contains descendant indirect object that is contained in another PDF document. (Parameter ‘item’)
at GemBox.Pdf.Objects.PdfBasicContainer.(PdfBasicContainer )
at GemBox.Pdf.Objects.PdfBasicContainer.lc8lpgped2564ebsf5tnlmfh9uj6jzaz(PdfBasicObject )
at GemBox.Pdf.Objects.PdfDictionary.lc8lpgped2564ebsf5tnlmfh9uj6jzaz(PdfBasicObject )
at GemBox.Pdf.Objects.PdfDictionary.(PdfName , PdfBasicObject , , Int32)
at GemBox.Pdf.Objects.PdfDictionary.Add(PdfName key, PdfBasicObject value)
at .(PdfName , )
at .( )
at.ee(PdfExternalObject )
at .(PdfImageContent )
at .(PdfContentElementCollection )
at .(PdfContentGroup )
at .(PdfContentElementCollection )
at .(e , PdfContentElementCollection )
at GemBox.Pdf.Content.PdfContent.EndEdit(Boolean force)
at GemBox.Pdf.Content.PdfContent.()
at GemBox.Pdf.Content.PdfContentElement()
at GemBox.Pdf.Content.PdfContentElementCollection()
at GemBox.Pdf.Content.PdfContentElementCollection.(PdfContentElement )
at GemBox.Pdf.Content.PdfContentElementCollection.(PdfContentElement , PdfContentElement )
at GemBox.Pdf.Content.PdfContentElementCollection.AddPath(PdfContentElement nextElement)

Not a reproducible project but stack trace at the time. Could be related to multi-threading also
The function I was calling is

var cell = page.Content.Elements.AddPath();

( Still not using the latest bugfix version )

As mentioned before, please use the latest version, and if the problem remains please send us something that we can use to troubleshoot the problem.

Managed to reproduce the issue. It was presenting on our current version 17.0.1208 and fixed in the latest stable version 17.0.1300. Thanks for the support