-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Form rendering differences for textboxes and checkboxes when generated with pypdf and Acrobat #3115
Comments
Please fill the complete template, including the code and a PDF file to allow us to reproduce your issues. Additionally, debugging might be easier if you are able to provide the original and the form as filled by Acrobat to look for the relevant differences. |
@stefan6419846 Apologies, I accidentally pressed Ctrl+Enter and submitted my issue half complete. I finished editing it now and it is complete. Let me know if more information is needed. Thanks! |
No worries. Unfortunately, without the requested PDF files (either provided publicly or privately) there is not much we can/will do here as this leads to just guessing. |
Ok understood. I will try to make a new PDF form that I can share, and reproduce the error. Stay tuned. |
@stefan6419846 I attached a PDF form with the described issue. |
Thanks for providing an example file, although analysis probably would be easier if we have a version of the form filled using Acrobat as well - from our experience, there might just be one attribute which is different. |
Ok, I added two more PDF files to my post. One is the pypdf output with described issues, and one that I manually filled using Acrobat which doesn't have the issues. Both used the same blank-form.pdf to start. Hope it helps. Thanks for your time! |
The text box looks rather similar, except that Adobe seems to position each character separately:
There is not much difference for the checkbox as well:
You are of course invited to further look into it and check which changes do indeed make the difference here. For now, I do not have enough time to dig deeper into this stuff myself. |
I've had time to compare the data behind the checkboxes. I spotted a difference in the /V values: pypdf checkbox
Acrobat checkbox
It's subtle, but there are no parentheses around the"/On" value (/V) in Acrobat's file. Test Fix Test PDF Form - pypdf filled - On value manual fix.pdf P.S.
Changing it to At first glance, it seems like we can fix the checkbox behaviour, but the text formatting still remains "broken" without manual intervention. That's all I can dig into for now. |
Feel free to submit a PR for this, although the PDF 2.0 specification states in section 12.7.5.2.3:
|
I have been able to pinpoint this to Lines 1107 to 1114 in 2263dcb
Line 1107 sets the Could you please test whether adding
after line 1114 solves your issue with the checkboxes? |
I added Test PDF Form - pypdf filled - line 1115 test fix.pdf Note that in my initial code, I had |
I have a PDF form I am trying to autofill. The form was made with Adobe Acrobat Pro, and it contains various textboxes and checkboxes.
I am able to add text entries in the textboxes, and when I open that output PDF in Adobe Acrobat, the file opens and the entries "render" properly.
However, the issue arises when I also check checkboxes. When I fill textboxes and checkboxes with pypdf, then opening the PDF form in Adobe Acrobat, the checkboxes aren't truly checked and all the formatting of the textboxes are broken (i.e. not rendered). Let me explain further.
Text in pypdf filled textboxes look like this:

The formatting only fixes itself if I manually modify the text entry with Adobe Acrobat:

Also, visually the checkboxes are checked :

However, if I manually click this checkbox once in Acrobat, the box remains checked (i.e. it was never ON in Acrobat's eyes?)

A second click then unchecks the box. In contract, checkboxes not touched by pypdf don't behave this way, the first click switches the checkbox to the opposite state, as expected.
Once I manually interact with the pypdf filled checkboxes in Acrobat, and save the document, then all the textboxes render properly upon re-opening. So in summary, checking checkboxes with pypdf breaks the rendering of all textboxes in Acrobat. And it seems like Adobe doesn't recognized the checkboxes as checked by pypdf.
Environment
Python 3.10.11, pypdf 5.2.0
After pypdf outputs the PDF, I view in Adobe Acrobat.
Note that this doesn't seem to be an issue when opening the PDF with Chrome. But for my purposes I must use Adobe Acrobat.
Code + PDF
Unfortunately I can't share the PDF file itself.Here is a redacted version of my PDF form. I cleared the PDF, other than the boxes of interest. The behaviour described above is still present in the remaining boxes.
blank-form.pdf
Test PDF Form - pypdf filled.pdf
Test PDF Form - Acrobat filled.pdf
The text was updated successfully, but these errors were encountered: