Editable .pdf fields disappear (but are visible in the focus of the field) after saving with evince

First of all, let me thank the SO community for helping me so many times in the past; you guys are an amazing resource!

At my work, I am working on a web application that uses PDF templates created in Scribus and iText Java to populate templates with data from our database. Sometimes a user-provided field is required and iText is not affected. When the .pdf is loaded, the field is edited and the copy is saved using Evince. As a result, the file will not display the edited text when it is reopened. However, when focusing the editable field, it displays the saved text. Nefocus, the text disappears. Cut text, paste back into the box; it remains visible until you save and reopen the document. After saving and reopening the original problem appears. I found many very similar posts on this issue, but none of the solutions for which seem to work for me.

In addition, the problem is bizarre. If I open the Scribus template (a PDF file not affected by iText) using Evince, then edit the fields and save them, they will display correctly when re-opened. However, if the library touches the template, a problem occurs. Similarly, I can reproduce the problem with the PDF files that I found while searching for the cause of this problem; like this:

http://www.quask.com/samples/pdfforms/pcpurchase.pdf

This makes me think that the wrong files may be damaged in some way and that iText may be causing my problem, but iText is not the only way in which I can reproduce the problem so that I don’t know what to think. I cannot find a working solution among the many that I have seen. Is anyone familiar enough with this problem to tell me where I can figure this out, or to offer some insight into the tools I use? Most likely, if you are looking for a problem using google, I saw it.

I am using Ubuntu 12.04 (exact), Evince 3.4.0, iText 2.1.5 and can try to fill you with any other relevant details upon request. I am afraid to publish any code, since I'm not sure if it is kosher, and it is great for building forms, except for this specific problem; not to mention that I can reproduce the problem without using our webapp.

This is my first post here, and I'm a beginner programmer (still at school!), So please let me know if I broke any conventions or could improve my future requests.

Thanks for any help you can offer!

+4
source share
2 answers

Checking the files provided by jbowman in the comments to his question - with particular regard to the password field (which is one of the fields filled through evince) --- shows:

Template.pdf

  • - This is the original form created by Scribus PDF Library 1.4.1.svn;
  • contains AcroForm with 9 fields, and the NeedAppearances flag is true,
  • has a password field (named passwordField) that contains an empty value, and a regular appearance stream draws a rectangle with empty text.

after_itext.pdf

  • - this is the original form edited by iText 2.1.5, unfortunately, not in add mode, which would facilitate analysis;
  • contains Acroform with 8 fields (element number field is filled and smoothed) without the NeedAppearances flag;
  • has a password field (named passwordField: u4woYY1FK9), and external values ​​remain untouched.

after_itext_edited.pdf

  • - a form previously edited by iText, now edited by some other software (evince) in add mode;
  • contains Acroform with 8 fields without the NeedAppearances flag; only changes were made to the passwordField: u4woYY1FK9 and memberPrefix: u4woYY1FK9 fields:
  • has a password field (named passwordField: u4woYY1FK9) with the new associated value asdf, but left it visible untouched;
  • has a member prefix field (named memberPrefix: u4woYY1FK9) with the new associated value asdf, but left it visible untouched.

Thus, the observed behavior, which is not shown by default, should be expected:

The Acroform Final does not have a NeedAppearances flag. This flag is defined in the specification ISO 32000-1: 2008 as:

A flag that determines whether to create appearance streams and dictionaries for all widget annotations in a document (see 12.7.3.3, "Variable Text"). The default value is false.

Thus, your PDF document in its final form says: "You do not need to see visibility for widgets (for example, visualization of AcroForm fields), call visibility from the document.

The appearance of the password field from the document is the original, a rectangle with empty text.

So you see this empty rectangle.

When you click in a field, the PDF viewer prepares to edit its contents and, therefore, displays the value as you like.

If editing PDF files with evince should have visible results, then when changing the field values, you must also add updated appearance streams or make sure that the AcroForm NeddAppearances flag is set. So this is where evince failed.

+4
source

I accepted mkl's answer as it strikes the nail on the head as to why the fields are not displayed properly and contains much more information than I can provide regarding the problem. However, the proposed fix in the comment comments did not work, because the documents were generated (in this particular case) using iText 2.1.5 PdfCopyFields , which does not take into account (removes) the original NeedAppearances flag and calls setNeedAppearances(true) for AcroForm could not be solved because of for that.

Hacking createAcroForms() method in PdfCopyFieldsImp to include a string

 form.put(PdfName.NEEDAPPEARANCES, PdfBoolean.PDFTRUE); 

- this is what ultimately seems to have solved the problem for me. With this addition, after correctly displaying the field changes after saving and reopening the document, you should make sure.

+1
source

Source: https://habr.com/ru/post/1446113/


All Articles