Q:
I think, I can solve the problem with the IRT entry, but I still have
another problem with multiple annotations. I tried a lot to get it to
work, but there are still double annots in my PDF file at the end.
First I did it like shown in the example (http://groups.google.com/
group/pdfnet-sdk/browse_thread/thread/
afc3ce3a1da7cfa5/0ff4691af0353538?lnk=gst&q=annotations
+server&rnum=1#0ff4691af0353538), but I got double annotations,
because all FDF annotations are imported at the beginning without a
check.
At last I tried to find new FDF annotations, that do not exist in the
PDF file, before I call the function pdftron::SDF::Doc::ImportObj. It
seems to work, but when I call pdftron::PDF::Page::AnnotPushBack after
the importObj function, I have multiple annots in my PDF again. The
class is along the following lines:
//-----
FDFDoc fDoc = new FDFDoc(fdfFile);
DictIterator fdfannotsIter = objFDF.Find("Annots");
if(fdfannotsIter == objFDF.DictEnd()) // if no /Annots entry in FDF
object
return;
Obj objFdfannots = fdfannotsIter.Value(); // get all FDF annots
for(int i=0; i<objFdfannots.Size(); i++) {
Obj objFdfannot = objFdfannots.GetAt(i); // a single FDF annotation
as Obj
Annot fdfAnnot = new Annot(objFdfannot); // a single FDF annotation
as Annot
if(!fdfAnnot.GetType().ToString().Equals("e_Popup")) { // popup
annots won't be imported (they are imported right after import of
other annots like text etc.)
// get page number for the FDF annotation
DictIterator fdfpageIter = objFdfannot.Find("Page");
if(fdfpageIter != objFdfannot.DictEnd()) {
int page_num = (int) fdfpageIter.Value().GetNumber() + 1;
// get page object in PDF
PageIterator pdfpageIter = pDoc.PageFind(page_num);
if(pdfpageIter == pDoc.PageEnd()) { // if there is no page with
that page number
return;
}
Page page = pdfpageIter.Current();
//if there exists an annot with the same NM-entry on the page
already
if(!existsInPage(page, fdfAnnot)) {
Obj importedAnnot = pDoc.GetSDFDoc().ImportObj(objFdfannot,
true);
Annot newAnnot = new Annot(importedAnnot);
page.AnnotPushBack(newAnnot);
// if annot has an IRT entry, change it to correct entry
...
// import popup for the annotation
...
} }
---
A:
The problem lies in multiple object imports. In your sample FDF, the
annotation has indirect link to the associated 'Popup' annotation and
the 'popup' annotation has a link to the parent annotation (i.e.
'Parent' entry in popup annotation dictionary). When you use
ImportObj() it will also import all referenced object form a given
object (so importing an annotation will also import its popup
annotation; and importing a popup annotation will import associated
parent annotation).
As a workaround, you can import all annotations at once. For example:
Obj imported_annots = pdfdoc.GetSDFDoc().ImportObj(objFdfannots,
true);
Where 'objFdfannots' corresponds to 'Annots' array in FDF document.
After this you can iterate over imported_annots similar to your sample
code, but you would not call ImportObjs() anymore.
In case you would like to import only some annotations from
'objFdfannots' array, it is not a problem. You would still import all
annotations as described above, however since not all annotations will
not be associated with PDF page (using AnnotPushBack()) they will be
automatically removed during pdfdoc.Save() (if you specify 'remove
unused object' or 'linearization' flag).