-
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
IndexError: string index out of range
when writing a PDF with set fields
#1713
Comments
@cmin764 |
@cmin764 |
@cmin764 from pypdf import PdfReader, PdfWriter
filepath = "test.pdf"
reader = PdfReader(filepath)
writer = PdfWriter(clone_from=reader)
writer.update_page_form_field_values(
writer.pages[0],
{
"CAC M": "/Oui",
},
)
writer.write("out.pdf") while this crashes: from pypdf import PdfReader, PdfWriter
filepath = "test.pdf"
reader = PdfReader(filepath)
writer = PdfWriter(clone_from=reader)
writer.update_page_form_field_values(
writer.pages[0],
{
"CAC M": "",
},
)
writer.write("out.pdf") Here is the traceback:
So I'm guessing your problem might come from (On Ubuntu 20.04.5, Python 3.11.2, pypdf 3.7.0) |
Yes that's right! I think you cracked the case and I'll come back to it as soon as it is reported again from our side. Btw, what would the author suggest as the default value when it is not provided by the user and we have to create the final output PDF? Would that be a |
I propose to close this issue. @MartinThoma do you think it should be converted into a discussion ? |
That sounds good, still, wouldn't be cool to treat this issue in the |
the problem is not pypdf but the PDF standard: you can write wrong data but if not correctly interpreted by viewers it is useless... |
I've spent some time studying fields and got more details:
|
the PR I've prepared should help you : get_fields will now return the acceptable states in "/States" virtual entry (applicable both to Checkbox, Radio Buttons, and Lists |
|
@pubpub-zz I know this is closed, but I'm having a question regarding the changes brought above: I observed that with the latest version (3.15.0) there's no
How do you recommend to retrieve and set fields in PDFs now? Any link to relevant docs and code changes and/or examples will be greatly appreciated! |
in order to copy the /Acroform entries you have to use either the |
When filling in fields with values (in the right page) I get the trace below when trying to save the resulting PDF into an output file.
Environment
On Mac M1 with Python 3.9.13 and
pypdf
3.5.2.Code + PDF
This is the library wrapping code I use:
I'll be sharing the problematic PDF file once I'm ensured it can be made public.
Traceback
This is the complete Traceback I see:
The text was updated successfully, but these errors were encountered: