fdfdoc = doc.FDFExtract(PDFDoc.e_both) # other options are e_forms_only, e_annots_only, e_annots_only_no_linksfdf = fdfdoc.GetFDF()annots = fdf.FindObj('Annots')new_annots = fdfdoc.GetSDFDoc().CreateIndirectArray()if annots != None and annots.IsArray(): for i in range(annots.Size()): annot_obj = annots_obj.GetAt(i) annot = Annot(annot_obj) # here you have an Annotation object, and you can now decide what to keep/remove if(this_is_annotation_i_want_to_export) new_annots.PushBack(annot_obj)
fdf.Put('Annots', new_annots) # replace old annots# now you can save as FDF binary format, or XFDF XML formatstring xfdf_xml = fdf.SaveAsXFDF()
myviewer.DocLock()
Obj p_obj = annot_to_export.GetSDFObj().FindObj("P")
annot_to_export.GetSDFObj().Erase("P")
// create temp doc and page
PDFDoc temp
Obj imported_annot_obj = temp.GetSDFDoc().ImportObj(annot_to_export.GetSDFObj(), true)
// put page back and release lock
annot_to_export.GetSDFObj().Put("P", p_obj)
myviewer.DocUnlock()
// create temp page, add, and add imported annot
Page temp_page = temp.PageCreate()
temp.PagePushBack(temp_page)
temp_page.AnnotPushBack(Annot(imported_annot_obj))
fdf = temp.FDFExtract(PDFDoc.e_both)
fdf.GetFDF().FindObj("Annots").GetAt(0).PutNumber("Page", original_page_number - 1) // PDF pages start at 1, but FDF pages start at zero.
xfdf_xml = fdf.SaveAsXFDF()
FDFDoc PDFDoc.FDFExtract(ArrayList annotations)