0

I created a PDF with Master PDF Editor containing one form text field. When manipulating that PDF file with iText7-Community I manage to find that field and to set its value. However, when I flatten the output PDF file that field is ripped and just disappears.

Bottom line: field shows up fine without flattening and disappears when flattening.

I ran isXfaPresent() from XfaForm and the response was false, so I understand it is indeed AcroForm.

So, this is what I tried:

PdfReader reader = new PdfReader("path-to-file.pdf");
PdfWriter writer = new PdfWriter("path-to-dest-file.pdf");
PdfDocument doc = new PdfDocument(reader, writer);

PdfAcroForm form = PdfAcroForm.getAcroForm(doc, false);
form.getField("treinamento").setValue(param);
System.out.println("----> " + form.getField("treinamento").value);
form.flattenFields();
doc.close();

System.out shows the value correctly setup but the output file doesn't show it. If I comment form.flattenFields() it does.

Any help on what I should do to fix this is greatly appreciated.

Sidney de Moraes
  • 993
  • 3
  • 11
  • 29

1 Answers1

0

Try call form.getField("treinamento").regenerateField(); after your call to setValue(...)

PdfReader reader = new PdfReader("path-to-file.pdf");
PdfWriter writer = new PdfWriter("path-to-dest-file.pdf");
PdfDocument doc = new PdfDocument(reader, writer);

PdfAcroForm form = PdfAcroForm.getAcroForm(doc, false);
form.getField("treinamento").setValue(param);
System.out.println("----> " + form.getField("treinamento").value);
form.getField("treinamento").regenerateField();
form.flattenFields();
doc.close();
Lonzak
  • 9,334
  • 5
  • 57
  • 88
  • Due to timeline, we ended up creating our PDF template with Scribus instead of PDF Master Editor. Sorry for not being able to test your suggestion but thanks for stopping by to help. – Sidney de Moraes May 14 '18 at 14:14