How to replace images if there is changes in the original one, and more than 1 reference in PDF doc?

The link:

https://groups.google.com/forum/?hl=en&fromgroups#!searchin/pdfnet-sdk/replace$20images/pdfnet-sdk/oWlA10uDOdk/gzYUqCCDxeEJ

provides information how to swap the original image with the modified one. This works, but what if there is say that same image in 3 different pages,
and all 3 images have been slightly modified? Bit if we are using sdf_doc.Swap() with orig_image.GetObjNum() and new_image.GetObjNum()…
isn’t the same obj num used in all 3 original places? Isn’t that so that if 3modified images are all slightly different, there should be replacement so
that every one of original orig_image (with just one obj num) would have 3 obj nums instead of 1?
I am using C++, so could you provide example in C++, please?

Hello Hannu,

You are correct that calling SDFDoc.Swap will change the image object in all places where it is referenced. In the scenario you describe, you would need to change each of the content streams which reference the image, changing the content streams to reference the new image.

To do so, traverse the page’s content as in the ElementEdit sample (https://www.pdftron.com/pdfnet/samplecode.html#ElementEdit). When you encounter the image in question (you can obtain the SDF object with Element.GetXObject()), you can create a new image with ElementBuilder (see https://www.pdftron.com/pdfnet/samplecode.html#AddImage) and add it in with ElementWriter.

To do so, traverse the page’s content as in the ElementEdit sample (https://www.pdftron.com/pdfnet/samplecode.html#ElementEdit). When you
encounter the image in question (you can obtain the SDF object with Element.GetXObject()), you can create a new image with ElementBuilder
(see https://www.pdftron.com/pdfnet/samplecode.html#AddImage) and add it in with ElementWriter.

Ok, but, isn’t it so that if I create new image, I should provide information regarding howto put the new image, because it is
possible that the original image can be eg partly behind another image, if there is say some artistic reasons for image layouts?
Possibly will never encounter that, but still… I mean that orig image rect info is not enough, I should provide info also how to
set the new image regarding other elements inside that specific page?

Hello Hannu,

I should provide info
also how to set the new
image regarding other
elements inside that
specific page?

You can find other information about other elements on the page when traversing the content stream with ElementReader. This is shown in the following code samples:

https://www.pdftron.com/pdfnet/samplecode.html#ElementEdit
https://www.pdftron.com/pdfnet/samplecode.html#ElementReader
https://www.pdftron.com/pdfnet/samplecode.html#ElementReaderAdv

The following describes how to test whether two Images (or other elements) overlap:

https://groups.google.com/d/msg/pdfnet-sdk/HAs84mNP4sM/IcZCpLA7m3IJ