Merging FDF (Forms Data) with PDF in an ASP.NET application.

Q:

I am merging FDF (Forms Data Format) data with PDF using PDFNet SDK as
follows:

int R;
byte[] zz;

PDFNet.Initialize();
PDFNet.SetResourcesPath(Server.MapPath(@"bin\resources"));
PDFDoc doc = new PDFDoc(Server.MapPath(URL));
doc.InitSecurityHandler();

Byte[] byteBLOBData = new Byte[0];
byteBLOBData = (Byte[])(ds.Tables["Index"].Rows[c - 1]["FDFData"]);
FDFDoc fdf_doc = new FDFDoc(byteBLOBData, byteBLOBData.Length);
doc.FDFMerge(fdf_doc);
doc.RefreshFieldAppearances();

Response.ClearContent();
Response.ClearHeaders();
Response.Clear();
Response.Cache.SetNoServerCaching();
Response.Cache.SetNoStore();
zz = null;
R = 0;
doc.Save(ref zz, ref R, 0);
doc.Close();
Response.Buffer = true;
Response.Expires = 0;
Response.ContentType = "application/pdf"; Response.AddHeader("Content-
Type",
"application/pdf"); Response.BinaryWrite(zz); Response.End();

The problem is that we have some PDF documents that extensively use
JavaScript that relies on old AP streams. FDFMerge erases old AP
streams causing the conflict with the JavaScript.

Is there a workaround or another way to merge FDF forms data with PDF?
----

A:

You could merge FDF forms data with PDF manually. For example,

void MyFDFMerge(FDF.FDFDoc fdf_doc, PDF.PDFDoc doc) {
  FDF.FDFFieldIterator itr = fdf_doc.FieldBegin();
  FDF.FDFFieldIterator end = fdf_doc.FieldEnd();

  for (; itr.Equals(end) == false; itr.Next()) {
    FieldIterator fi = doc.FieldFind(itr.Current().GetName());
    if (fi.Equals(doc.FieldEnd()) == false) {
      Obj val = itr.Current().GetValue();
      if (val != null && val.IsStream() == false && val.IsNull() ==
false) {
        fi.Current().SetValue(val.Clone());
      }
    }
    else {
     fi.Current().SetValue(SDF.Obj.CreateNull());
    }
  }

  doc.RefreshFieldAppearances();
}

'MyFDFMerge' is a stripped down version of pdfdoc.FDFMerge(fdf). It
doesn't include FDF annotation merging, etc... , but it will resolve
the problem with the embedded JavaScript. In any case, you have full
control over how FDF forms data is merged with PDF.