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

Calling check() after generate_appearance_streams() #506

Open
rxw1 opened this issue Jul 31, 2023 · 0 comments
Open

Calling check() after generate_appearance_streams() #506

rxw1 opened this issue Jul 31, 2023 · 0 comments

Comments

@rxw1
Copy link

rxw1 commented Jul 31, 2023

Hello,

not sure if this is expected behaviour:

Calling check() after generate_appearance_streams() seems to remove the effect of setting pdf.Root.AcroForm.NeedAppearances = True and may lead to the form field contents not being rendered.

Calling check() before generate_appearance_streams() or not calling generate_appearance_streams() does not have that consequence.

A somewhat minimal example:

from pikepdf import Pdf, Name

annotation_data = {
    "Text1": "Hello",
    "Text2": "World",
}

with Pdf.open("example1.pdf") as pdf:
    for page in pdf.pages:
        annots = page.Annots
        if annots is not None:
            for annot in annots.as_list():
                key = str(annot.T)
                if annot.FT == Name("/Tx"):
                    if key in (annotation_data or {}):
                        value = annotation_data.get(key)
                        if value and value.strip():
                            annot.V = value
                            annot.Ff = 1

    pdf.Root.AcroForm.NeedAppearances = True
    pdf.generate_appearance_streams()
    pdf.check()

    pdf.save('example1-modified.pdf')

example1.pdf

Best regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant