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

Signed Signature Field gets deleted after update_page_form_field_values() #1790

Open
liam-meak opened this issue Apr 15, 2023 · 2 comments
Open
Labels
workflow-forms From a users perspective, forms is the affected feature/workflow

Comments

@liam-meak
Copy link

I am developing a script to automatically fill out the 'Nr' field in a timesheet form.
The forms are digitally signed before they get a number.

When updating the 'Nr' field using writer.update_page_form_field_values() the signed signature field gets deleted.
Another signature field, which has not been signed at this point, has the expected behaviour.

This happened only when using:

writer.append(reader,[0])

Before I had the issue that all radio buttons were deleted but the signature was not.
This happend when using:

page = self._reader.pages[0]
writer.add_page(page)

Environment

Which environment were you using when you encountered the problem?

$ python -m platform
Windows-10-10.0.19045-SP0

$ python -c "import Pydf2;print(pypdf.__version__)"
3.0.1

Code + PDF

This is a minimal, complete example that shows the issue:

from PyPDF2 import PdfReader, PdfWriter

file = 'v2 - signed.pdf'

reader = PdfReader(file)
writer = PdfWriter()

writer.append(reader,[0])

writer.update_page_form_field_values(
    writer.pages[0], {'Nr':'SN230001'}
)
        
with open (file, 'wb') as stream_out:
    writer.write(stream_out)
    stream_out.close()

This is the form that is used. I just deleted personal informations from the form:
v2 - unsigned.pdf

This is the signed form:
v2 - signed.pdf

And this is the file after updating the form field:
v2 - after updating.pdf

@liam-meak liam-meak reopened this Apr 15, 2023
@neversphere
Copy link
Contributor

This is probably the same problem I had. I think the docs are wrong. Try appending the reader rather than just copying over a page:

reader = PdfReader(argv[0])
writer = PdfWriter()
writer.append(reader)

I have #1806 out to fix the docs.

MartinThoma pushed a commit that referenced this issue Apr 23, 2023
Update docs to use append rather than add_page so that the PDF structure is copied. This ensures the form structure is kept which is necessary for some PDFs.

See #1790
Closes #1792
Closes #1804
@liam-meak
Copy link
Author

@neversphere Thanks for the reply, I tested your suggestion and the signed signature field and radio buttons stay intact.
But this still raises another problem because now the unsigned signature field gets deleted from the form

Seems like there are still issues copying the original structure of the pdf

@stefan6419846 stefan6419846 added the workflow-forms From a users perspective, forms is the affected feature/workflow label Feb 15, 2024
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

3 participants