chinapandaman / PyPDFForm

:fire: The Python library for PDF forms.
https://chinapandaman.github.io/PyPDFForm/
MIT License
438 stars 19 forks source link

PPF-749: Improve Integer and Float Input Handling in PdfWrapper.fill() Method #749

Closed alexperedel closed 1 month ago

alexperedel commented 1 month ago

Version

PyPDFForm=1.4.36

Issue Description

This issue aims to improve the validation and handling of integer and float values in the PdfWrapper.fill() method to ensure they are appropriately converted to strings before being filled into the PDF form.

Code Snippet

from PyPDFForm import PdfWrapper

filled = PdfWrapper("sample_template.pdf").fill( { "test": "test_1", "check": True, "test_2": 33, "check_2": False, "test_3": "test_3", "check_3": True, }, )

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


from PyPDFForm import PdfWrapper

filled = PdfWrapper("sample_template.pdf").fill( { "test": "test_1", "check": True, "test_2": 42.8, "check_2": False, "test_3": "test_3", "check_3": True, }, )

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

PDF Form Template

sample_template.pdf

Screenshots (if applicable)

image

image

alexperedel commented 1 month ago

Hi! I've already resolved this issue locally and covered with tests. I got 100% passed by running this all the tests "coverage run -m pytest". The problem was related to how the PdfWrapper.fill() method handled integer and float values, and I made sure they are correctly converted to strings before filling the PDF form. Could you please assign it to me?

chinapandaman commented 1 month ago

Hey thanks for reaching out.

The design philosophy behind the library is believing in duck typing. So in this specific case you should be filling test_2 using the string "33" instead of the integer 33.

But I think a bit more handling doesn't hurt in this case. Go ahead and open a PR.