How can I copy an image from one document to another?

Q:

We’ve been trying to make a new PDF file, copying an image from one document to another. We wrote a sample code to test on copying images. But the code kept giving us exception and didn’t work what we planned it to work. This is what was shown on the screen.

Exception:
Message: Objects cannot belong to different documents
Conditional expression: this_doc == obj->GetDoc()
Filename : Dict.cpp
Function : trn::SDF::Dict::Put
Linenumber : 104

A:

Each pdftron::PDF::Image object is created within the context of PDFDoc or SDFDoc. Thus you would need to create a new Image within the target document, using Image::Create:

http://www.pdftron.com/pdfnet/PDFNetC/d2/d12/classpdftron_1_1_p_d_f_1_1_image.html

Alternately, you could copy the entire page over to the new document (as shown in http://www.pdftron.com/pdfnet/samplecode.html#PDFPage), then copy the Image between pages.

None of these links working…it goes to a page not found screen

We get this issue when creating multiple PDF pages and need your help to resolve it.

Exception:
Message: Objects cannot belong to different documents
Conditional expression: this_doc == obj->GetDoc()
Version : 10.6.0-d8c2f1d741
Platform : Windows
Architecture : AMD64
Filename : Dict.cpp
Function : trn::SDF::Dict::Put
Linenumber : 170