Skip to content
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

Update Text Field Values Generates Text Behind The Text Field #1618

Closed
AhmedAlZabidi opened this issue Feb 8, 2023 · 5 comments
Closed

Update Text Field Values Generates Text Behind The Text Field #1618

AhmedAlZabidi opened this issue Feb 8, 2023 · 5 comments
Labels
workflow-forms From a users perspective, forms is the affected feature/workflow

Comments

@AhmedAlZabidi
Copy link

AhmedAlZabidi commented Feb 8, 2023

1- We created a simple empty word document and then convert it to a pdf
2- We prepared a form by adding a text field (we named it 'due_date') to the pdf file
3- We saved the pdf file
3- We run the below script to generate a new filled pdf file
4- We opened the newly generated file and we could not see the updated values. Note: when we click on the text field, the updated value appears. Also, when we open the file in Google chrome browser, the updated values will be shown

Environment

Python 3.8.10

Code + PDF

from pypdf import PdfReader, PdfWriter

reader = PdfReader("test.pdf")
writer = PdfWriter()

page = reader.pages[0]
fields = reader.get_fields()

writer.add_page(page)

writer.update_page_form_field_values(
    writer.pages[0], {
        'due_date': 'hello'
    }
)

# write "output" to PyPDF2-output.pdf
with open("filled-out.pdf", "wb") as output_stream:
    writer.write(output_stream)

The input file:
test.pdf

The output file:

filled-out.pdf

@3sticks
Copy link

3sticks commented Feb 10, 2023

Having this same problem myself. Added text will not show up until clicking on the text field, unless opened in a browser.

@SteffoSpieler
Copy link

Having the same issue too. Also when trying to print the pdf from the browser (e.g. Firefox), then the text fields are empty again.

@MartinThoma MartinThoma added the workflow-forms From a users perspective, forms is the affected feature/workflow label Mar 14, 2023
@csears123
Copy link

This is related to issue #355

@pubpub-zz
Copy link
Collaborator

pubpub-zz commented May 29, 2023

I've been able to get the text displayed using append() (https://pypdf.readthedocs.io/en/stable/user/merging-pdfs.html#add-page-insert-page)
it is copying the fields tree whereas append_page doesn't:

from pypdf import PdfWriter

writer = PdfWriter()
writer.append("test.pdf")

writer.update_page_form_field_values(
    writer.pages[0], {
        'due_date': 'hello'
    }, auto_regen=False,
)
writer.write("filled-out.pdf")

edit:
PR #1864 adds static text generation (auto_regen=False)

@pubpub-zz
Copy link
Collaborator

this issue is closed with #1864.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
workflow-forms From a users perspective, forms is the affected feature/workflow
Projects
None yet
Development

No branches or pull requests

6 participants