1

I use iTextSharp to populate fields in a PDF. I would like the PDF to stay editable when the user opens it (i.e. so I can't flatten the PDF).

The problem is that when I stamp the PDF and view the values in Adobe Reader the fields remain blank. If I stamp the PDF, and flatten it, and then view the values then the fields do in fact have values.

How can I populate fields and keep the PDF editable?

Here's my method as an ASP.NET MVC action:

public ActionResult GetPdfTWOWithSurname()
{
        PdfHelpers _pdfHelper = new PdfHelpers(Server, Url, "~/Content/newForm.pdf");
        var outStream = new MemoryStream();
    var pdfReader = new PdfReader(_pdfHelper.GetPdfBytes());
        var pdfStamper = new PdfStamper(pdfReader, outStream, '\0', true); //The 'true' value is important. Otherwise the document loses some dynamic features.
    pdfStamper.Writer.CloseStream = false;
    pdfStamper.FormFlattening = false; //Allow editing after close.


    var fields = pdfStamper.AcroFields;

    //Fill in text fields...
        fields.SetField("topmostSubform[0].Page2[0].InvestorDetails_Surname[0]", "This is a surname");
    pdfStamper.Close();

    //Get outStream bytes and return...
    outStream.Seek(0, SeekOrigin.Begin);
    byte[] outBytes = new byte[outStream.Length];
    outStream.Read(outBytes, 0, (int)outStream.Length);

    return File(outBytes, "application/pdf", "ThePdfFileTWO.pdf");
}

Note that this PDF is reader enabled, and I assume it stays that way even after the save since Adobe reader shows the "Extended" toolbox when I open the file. And the fields remain editable.

Also note that the PDF remains editable, and the fields have values... in FoxitPDF reader.

Please HELP

willem
  • 22,847
  • 19
  • 68
  • 110

2 Answers2

0

I have that same issue and it only happens if the PDF was created with Adobe Acrobat with Extended Features. Only option I've found is to re-create the form so that pop-up box has no reason to pop-up. GL

Ben Petersen
  • 401
  • 3
  • 15
0

http://what-when-how.com/itext-5/preserving-the-usage-rights-of-reader-enabled-forms-itext-5/

  • set FormFalttering to False and set RemoveUsageRights() (depends from the iText version)
Gregory W
  • 11
  • 4