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

Boxes disappear on fill #704

Open
AaronWGoh opened this issue Jul 16, 2024 · 3 comments
Open

Boxes disappear on fill #704

AaronWGoh opened this issue Jul 16, 2024 · 3 comments

Comments

@AaronWGoh
Copy link

Version

PyPDFForm==1.4.31

Issue Description

The PDF form field boxes disappear and the styling of the entire pdf changes with the basic out of box documentation.

Code Snippet

input_pdf = <file_path>
from PyPDFForm import PdfWrapper

wrapper = PdfWrapper(input_pdf)
data = wrapper.sample_data

keys_to_delete = [key for key in data if "Signature" in key]
for key in keys_to_delete:
    del data[key]

filled = wrapper.fill(
    {
        "VA_File_Number[0]": "123456789",
        "Veteran_Service_Member_First_Name[0]": "Samuel",
    },
)

with open("output.pdf", "wb+") as output:
    output.write(filled.read())

PDF Form Template

file.pdf
Above is pdf used to replicate example

Screenshots (if applicable)

Initial pdf looks like
image

After the code is run, it becomes
image

@chinapandaman
Copy link
Owner

Hey, thanks for posting, and sorry for a rather late response.

This is actually an intended behavior of PdfWrapper. The "box like looks" are I believe part of the widget styles, which as described at the top of this doc, all widgets will be flattened after filling. Now in the case of PdfWrapper flattening widgets means removing them and only leaving the text, which is why there are no more box styles.

If you still want to persist the box styles, I suggest taking a look at the FormWrapper , documented here. Below is a result of me using your snippet except using FormWrapper:

output.pdf

@AaronWGoh
Copy link
Author

@chinapandaman I saw in the source code that PdfWrapper inherits from FormWrapper. I'd prefer to use the PdfWrapper as it appears there are other features tied to it such as merging pdfs & signing pdfs with images. Without digging too deep, are there ways around flattening the widgets in PdfWrapper?

@chinapandaman
Copy link
Owner

Unfortunately no.

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

2 participants