When I FDFMerge() annotations into a PDF and save it the annotations are not visible when opening the PDF in google chrome's pdf viewer. The annotations are visible when opening the same file directly from acrobat, or when opening in PDFTron's WebViewer.
If I open a PDF which has been FDFMerge()d but not working in chrome viewer I can open and save the file in acrobat, at which point the issue goes away.
Is there something I need to do after FDFMerge() to get these annotations to behave the exact same way as the acrobat workaround? Is some layer not being fully created?
Annotations in a PDF can have what is called an Appearance Stream, which is the explicit description of what it should look like. If it is missing, then at the time of viewing, most PDF readers will generate a new Appearance Stream based off of the properties of the Annotation.
However, Chrome will not generate these Appearance Streams, it will only read existing ones. If they are missing, the annotation will not appear at all.
Safari on the other hand ignores the Appearance Stream and always generates its own based on the Annotation properties.
Acrobat is detecting that there is no Appearance Stream, and adds it, which is why the annotations show in Chrome after saving with Acrobat.
To answer your actual question, add the following code after FDFMerge.
PageIterator itr = doc.GetPageIterator();
for (; itr.HasNext(); itr.Next())
{
System.Console.WriteLine("Page {0:d}: ", itr.GetPageNumber());
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() == false) continue;
if (annot.GetAppearance() == null)
{
// generate missing appearance
annot.RefreshAppearance();
}
}
}
This will ensure every annotation has an Appearance Stream, but avoids overwriting existing ones.