How do I copy annotations from one PDF to another?

546 views
Skip to first unread message

Support

unread,
Dec 17, 2018, 4:20:04 PM12/17/18
to pdfne...@googlegroups.com
Q: Is it possible to copy annotations from one PDF document to another
using the high-level API?  I tried to copy an Annot from one PDFDoc to
another using Page::AnnotPushBack(), but I got an error.

Exception: Message: Objects cannot belong to different documents

Or do I have to use the low-level API and try to “rebuild” the
annotation?

--------------------
A: You could either recreate the annotation or you could copy the low-
level object as follows:

Obj src_annot = annot.GetSDFObj();
src_annot.Erase("P");  // Erase P entry to prevent import
of the associated page.
Obj dest_annot = to_pdf.GetSDFDoc().ImportObj(src_annot, true);
Annot dest = new Annot(dest_annot);
Reply all
Reply to author
Forward
0 new messages