How do I generate appearances for annotations in a XFDF file?

I have annotations in a XFDF file, and I want to make sure that these have new appearances generated after merging into my PDF file.

However, I only want those newly merged annotations to have the refresh. Any existing should be left alone.

Since annotations in a XFDF are required to have a unique ID, we can rely on that find the annotations and refresh, using the following code.

Note, starting with PDFNet 7.2 there will be a single API call to take care of all this for you. In the meantime, use this code.

var fdfdoc = new FDFDoc(FDFDoc.CreateFromXFDF(pathToXfdf));
HashSet<string> ids = new HashSet<string>();
Obj fdfroot = fdfdoc.GetRoot();
Obj fdfdict = fdfroot.FindObj("FDF");
Obj annotsarray = fdfdict.FindObj("Annots");
if (annotsarray == null || !annotsarray.IsArray()) return;
int annots_sz = annotsarray.Size();
for (int i = 0; i < annots_sz; ++i)
Obj annotobj = annotsarray.GetAt(i);
Annot annot = new Annot(annotobj);
for (PageIterator itr = pdfDoc.GetPageIterator(); itr.HasNext(); itr.Next())
Page page = itr.Current();
for (int i = 0; i < page.GetNumAnnots(); ++i)
Annot annot = page.GetAnnot(i);
if (!annot.IsValid()) continue;
Obj o = annot.GetUniqueID();
if(o != null && o.IsString())
string id = o.GetAsPDFText();