BUG: Write /Root/AcroForm in set_need_appearances_writer#1639
BUG: Write /Root/AcroForm in set_need_appearances_writer#1639MartinThoma merged 1 commit intopy-pdf:mainfrom
Conversation
Codecov ReportBase: 91.92% // Head: 91.92% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #1639 +/- ##
==========================================
- Coverage 91.92% 91.92% -0.01%
==========================================
Files 33 33
Lines 6375 6374 -1
Branches 1272 1272
==========================================
- Hits 5860 5859 -1
Misses 327 327
Partials 188 188
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
|
Nevermind, doesn't quite work yet, seemingly only renders the first page correctly in Adobe Acrobat. |
|
I'll reopen this, because this does seem to fix |
|
@cryzed, |
# Taken from https://pypdf.readthedocs.io/en/stable/user/forms.html
from pypdf import PdfReader, PdfWriter
reader = PdfReader("Get_Started_With_Smallpdf.pdf")
writer = PdfWriter()
page = reader.pages[0]
fields = reader.get_fields()
writer.add_page(page)
writer.update_page_form_field_values(
writer.pages[0], {"test_field": "some filled in text"}
)
# write "output" to pypdf-output.pdf
with open("filled-out.pdf", "wb") as output_stream:
writer.write(output_stream)
|
|
import pyppdf
w = pypdf.PdfWriter()
w.append("filledGet_Started_With_Smallpdf.pdf", [0])
w.update_page_form_field_values(w.pages[0], {"test_field": "some filled in text"})
w.write("tt.pdf")Although your change is a good idea 😊 |
|
This patch does work for me in Adobe Acrobat (2022.003.20322), PDF-XChange and Edge browser but does not work in Chrome or Vivaldi browser. |
|
@pubpub-zz Do you think this PR improves pypdf? Or is there an issue we need to address before merging? |
|
the new code is better than the old one. and may explain why Acrobat reader may have some difficulties to read some files. For me you can merge it. |
|
@cryzed Thank you for your PR 🙏 I'm sorry it took so long until it was merged. I misunderstood a part of the conversation and thought there was an issue with the PR + I had some health issues (luckily all good again :-) ) Your fix will be part of the next release, likely on 12.05.2023 with |
|
If you want, I can add you to https://pypdf.readthedocs.io/en/latest/meta/CONTRIBUTORS.html :-) |
Sure, sounds good to me, if you think this was an adequate contribution! |
PdfWriter.set_need_appearances_writer() (whether called directly or indirectly by PdfWriter.update_page_form_field_values()) fails to create the /Root/AcroForm object correctly when it doesn't already exist in the PdfWriter object.
See my comment here for more details.
Fixes #355