Q:
I’ve imported an annotation with a custom color (i.e., specified in the annotation’s default appearance) from an XFDF document. But the custom colour doesn’t show up. Why?
A:
You need to call RefreshAppearance on the annotation:
PDFDoc doc((input_path + “test.pdf”).c_str());
doc.InitSecurityHandler();
FDFDoc fdf_doc2(FDFDoc::CreateFromXFDF(
(input_path + “test.xfdf”).c_str()));
doc.FDFMerge(fdf_doc2);
doc.RefreshFieldAppearances();
for (PageIterator itr = doc.GetPageIterator();
itr.HasNext();
itr.Next())
{
Page page = itr.Current();
int num_annots = page.GetNumAnnots();
for (int i=0; i<num_annots; ++i)
{
Annot annot = page.GetAnnot(i);
if (!annot.IsValid()) continue;
annot.RefreshAppearance();
}
}
doc.Save((output_path + “test_merged.pdf”).c_str(),
SDFDoc::e_linearized, 0);