How do I copy annotations from one PDF to another?

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);