AcroForm values missing after flattening

Viewed 5311

I'm using LibreOffice 4.1.3.2 to produce a fillable PDF:

  1. Created a Writer document
  2. Set some text and test fields
  3. Exported to PDF

Opening pdf file with Acrobar Reader shows a correct fillable pdf.
Next I use iTextSharp 5.4.5 to fill fields and save flattened document:

var pdf = new PdfReader(srcFilename);
using (var fw = new FileStream(dstFilename, FileMode.Create))
{
    var stamper = new PdfStamper(pdf, fw);
    var f = stamper.AcroFields;

    f.SetField("field1", "John Doe");
    f.SetField("field2", "12/04/2013");
    stamper.FormFlattening = true;
    stamper.Close();
}
pdf.Close();

Problem is that filled fields values completely disappear in new document!
I thought fields were not found or filled, but discovered that commenting stamper.FormFlattening = true field values are there in saved pdf!!
Naturally I need a flattened pdf...

Is there a solution for this?

2 Answers

It worked with me after adding the following line:

f.SetNeedAppearances(true);
Related