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

File does not seem to be saved #1903

Closed
bobweasel opened this issue Jun 21, 2023 · 12 comments · Fixed by #2151
Closed

File does not seem to be saved #1903

bobweasel opened this issue Jun 21, 2023 · 12 comments · Fixed by #2151
Labels
needs-pdf The issue needs a PDF file to show the problem

Comments

@bobweasel
Copy link

bobweasel commented Jun 21, 2023

After performing the write, I opened it in Adobe Acrobat Pro DC, and saw the edits are applied. However, when I try to close the file, I am promoted to save the file. If I click no, I would be prompted every time I open and close the file. However, when I try to attach the file in an email and preview it, the edits are no longer visible. This is solved by clicking yes on the save dialog instead, and I noticed that the file size increases after that.

Environment

Which environment were you using when you encountered the problem?

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


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

Code + PDF

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

from pypdf import PdfReader, PdfWriter

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

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

writer.append(reader)

writer.update_page_form_field_values(
    writer.pages[0], {
        "Given Name Text Box": "asdf",
        "Family Name Text Box": "fam",
        "Address 1 Text Box": "add1",
        "House nr Text Box": "2",
        "Address 2 Text Box": "add2",
        "Postcode Text Box": "123456",
        "City Text Box": "city",
        "Country Combo Box": "Belgium",
        "Gender List Box": "Man",
        "Height Formatted Field": "30",
        "Driving License Check Box": "city",
        "Favourite Colour List Box": "Black",
        "Language 1 Check Box": "/Yes",
        "Language 2 Check Box": "/Off",
    }
)

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

Share here the PDF file(s) that cause the issue. The smaller they are, the
better. Let us know if we may add them to our tests!
http://foersom.com/net/HowTo/data/OoPdfFormExample.pdf

Traceback

This is the complete Traceback I see:

No traceback

@pubpub-zz
Copy link
Collaborator

@bobweasel
.update_page_form_field_values() has a new param auto_regenerate which affects need_appearances flag. it can take 3 values:
True/False which set/clear the flag and None to keep the old value
when True this flag as the viewer to refresh the appearance based on from the "/V" field and the document is asked to be saved.
Unfortunately for history reason reason the default value is True. add ,auto_regenerate = False which should prevent the behavior you are observing.

@bobweasel
Copy link
Author

It's not working, setting the value to False or None results in the values not showing up at all.

@kubaPod
Copy link

kubaPod commented Jul 5, 2023

Just looking around for similar issue and tried your example.
It worked for me on Win 10 pypdf 3.12.0
Btw: "Driving License Check Box": "city", should be "/Yes", right?

@pubpub-zz
Copy link
Collaborator

@kubaPod Can you publish your output pdf ?

@kubaPod
Copy link

kubaPod commented Jul 6, 2023

@pubpub-zz sure:

filled-out.pdf

generated with:

from pypdf import PdfReader, PdfWriter

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

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

writer.append(reader)

writer.update_page_form_field_values(
    writer.pages[0], {
        "Given Name Text Box": "asdf",
        "Family Name Text Box": "fam",
        "Address 1 Text Box": "add1",
        "House nr Text Box": "2",
        "Address 2 Text Box": "add2",
        "Postcode Text Box": "123456",
        "City Text Box": "city",
        "Country Combo Box": "Belgium",
        "Gender List Box": "Man",
        "Height Formatted Field": "30",
        "Driving License Check Box": "/Yes", # also changed
        "Favourite Colour List Box": "Black",
        "Language 1 Check Box": "/Yes",
        "Language 2 Check Box": "/Off",
    },
    auto_regenerate = False
)

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

@pubpub-zz
Copy link
Collaborator

@bobweasel
can you confirm you are getting the same results as @kubaPod so we can close this issue

@bobweasel
Copy link
Author

bobweasel commented Jul 12, 2023

Hmm might be something to do with the file policy? I can't post the PDF here due to confidentiality reasons, but the problem still persist. See if someone else encounters it.

@pubpub-zz
Copy link
Collaborator

pubpub-zz commented Jul 12, 2023

Can you send it to @MartinThoma info@martin-thoma.de by mail?

@pubpub-zz
Copy link
Collaborator

@bobweasel : +1?

@pubpub-zz pubpub-zz added the needs-pdf The issue needs a PDF file to show the problem label Jul 26, 2023
@pubpub-zz
Copy link
Collaborator

I'm closing this issue until you can send the pdf else nothing can be done

@pubpub-zz pubpub-zz closed this as not planned Won't fix, can't repro, duplicate, stale Jul 26, 2023
@bobweasel
Copy link
Author

@pubpub-zz just sent to the indicated email

@pubpub-zz
Copy link
Collaborator

pubpub-zz commented Sep 5, 2023

@bobweasel
Sorry for coming so late : I've found an strange thing in your file: there is multiple spaces in the DA field of the annots after the font Inducing an issue that is now solved.

the PR is available if you want to test.

I've observed an odd result when filling the form : the spacing is not respecting the 'cases' : the current appareance we are generating does not cope with comb flag. I will open a new PR with a free form for people to help to find how to do it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-pdf The issue needs a PDF file to show the problem
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants