1

i have a PDF template containing a form. At present, I'm using itextpdf to fill the form fields, and save the resulting pdf.

Is there a way to get completeley rid of the pdf form (i.e. converting the pdf to a form-free pdf containing the inserted data)?

Mr.Radar
  • 775
  • 1
  • 11
  • 32
  • Have you tried flattening your pdf in iText? [They even have good documentation for this](http://itextpdf.com/examples/iia.php?id=163) – Benjamin Diele Jan 07 '15 at 07:33

1 Answers1

1

You need to set setFormFlattening to true on your PdfStamper object.

Code is from their documentation:

    for (Movie movie : PojoFactory.getMovies(connection)) {
        if (count == 0) {
            baos = new ByteArrayOutputStream();
            reader = new PdfReader(RESOURCE);
            stamper = new PdfStamper(reader, baos);
            stamper.setFormFlattening(true);
            form = stamper.getAcroFields();
        }
        count++;
    }
    if (count > 0) {
        stamper.close();
        reader = new PdfReader(baos.toByteArray());
        copy.addPage(copy.getImportedPage(reader, 1));
    }

That way the form will be flattened when you close your PdfStamper.

Benjamin Diele
  • 1,177
  • 1
  • 10
  • 26
  • doing so results in a corrupted pdf file - adobe reader tells that the file needs to be opened with a newer version although I'm using the newest one. (The pdf template was generated using adobe LiveCycle) Any idea on this? – Mr.Radar Jan 07 '15 at 20:55
  • @Mr.Radar I'm afraid I can't help you debug as I don't have a license for iText :( – Benjamin Diele Jan 07 '15 at 20:56