I am attempting to use automation to fill out an IRS form 941. I can do it will Excel which allows me to emulate key strokes when I have the form open in Acrobat Reader. Can save as and the completed form can be opened, viewed, edited and saved. I wanted a more deliberate way to do it and created a Python application following a paradigm suggested by several web postings including publishing in a conference journal. All of these suggested setting a NeedAppearances = True in the AcroFrom Annotation section of the dictionary. It was said this was required to make the filled out form viewable. However my code was successful in populating the form as I wrote a companion script to read the form after it was saved with a new name. Howver when this form file is open with Acrobat Reader, it is blank on the screen and also when I click on a cell I get a pop up saying the form cannot be saved, only printed. I also tried may scripts to open and immediately close the form to a new name and same problems even though nothing was altered. Why a different behavior when saving with a Python script versus what I can do manually in Acrobat Reader?
Not sure that is true. The Python script works perfectly in regard to substitution into blank fields. So the underlying AcroForm dictionary is being utilized and the script works without errors. As I noted I can save the file and reopen with a new read and I can see the values from the substituted fields in my script. The issue is that after using Python, if I open the saved file with Acrobat Reader the fields do not display. This is a known issue as documented in several references including this from a published report.
NeedAppearances property in the interactive form dictionary, AcroForm (See § 12.7.2) needs to be set, without this, the fields are updated but will not necessarily display. To remedy this, the following code snippet can be used. pdf.Root.AcroForm.update(PdfDict(NeedAppearances=PdfObject('true')))
This is in my code but does not affect the behavior of the substituted form when reeopend.