Workaround for PDF forms containing bad or missing appearance streams.

Q:

During rendering of a small number of PDF documents we loose the data
on the form. What is the reason for this and is there a workaround?
----
A:

We looked in all test files and problem is in the PDF producer that
generated PDF. Specifically form appearance streams are missing for
most widgets and 'NeedAppearances' flag in AcroForm dictionary is set
to true. This is why Acrobat Pro will prompt you to save the document
when closing document's window.

You can use PDFNet SDK to regenerate missing appearance streams using
pdfdoc.RefreshFieldAppearances() method. So after opening a PDF
document you can use the following code to rebuild widget appearance
streams:

Obj acro_form = pdfdoc.GetAcroForm()
if (acro_form != null) {
  Obj need_ap = acro_form.FindObj("NeedAppearances")
  if (need_ap!=null && need_ap.IsBool() && need_ap.GetBool() == true )
{
    doc.RefreshFieldAppearances();
  }
}