I'm using LibreOffice 4.1.3.2 to produce a fillable 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?
When creating a form using Open Office, Open Office sets a flag telling iText not to create appearances. If you look at the FillDataSheet example, you'll see that we override this with the following line:
fields.setGenerateAppearances(true);
In your specific C# snippet, that would be:
f.GenerateAppearances = true;
It's important to set this value before setting the fields or the appearances won't be created.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With