PyPDFForm icon indicating copy to clipboard operation
PyPDFForm copied to clipboard

The content of fields filled with FormWrapper only appear on click when opened with Adobe Acrobat

Open plapointe6 opened this issue 9 months ago • 7 comments

Hello,

Your library is really nice and easy to use.

I have an issue with FormWrapper. When I fill with FormWrapper, the content of filled fields only appear on click. This seems to work when opening the pdf with Chrome, but not with Adobe Acrobat.

My code:

from PyPDFForm import FormWrapper

filled = FormWrapper("report.pdf",).fill(
    {
        "301 Full name": "John Smith",
        "301 Address Street": "1234 road number 6",
    },
    flatten=True
)

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

Input pdf: report.pdf Result pdf: filled.pdf

Screenshot with adobe acrobat. The first field, I just clicked on it, so we see it's content. The second one is filled, but we will see it's content only on click. image

Thanks !

plapointe6 avatar May 07 '24 17:05 plapointe6

Hey, thanks for posting.

The issue you ran into was somewhat discussed in another thread, specifically I did a rather detailed explanation here.

In short, Adobe Acrobat seems to require way more complex metadata than browsers like Chrome for a text field widget to be rendered properly. This level of complexity is something that I'm unable to implement unfortunately. This is the largest reason why PdfWrapper exists in the first place.

chinapandaman avatar May 08 '24 00:05 chinapandaman

Thanks. The only downside of PdfWrapper is that it does not implements automatic font size depending of the content as FormWrapper do when the fields are correctly configured in the pdf. This cause me issues as the text overflow instead of reducing its size. especially for multi-line fields.

plapointe6 avatar May 08 '24 12:05 plapointe6

It’s normal for regular text field to overflow but that shouldn’t be the case for multi-line paragraph field. Could you post me an example?

Edit: unless for paragraph field it overflows vertically?

chinapandaman avatar May 08 '24 13:05 chinapandaman

Only for multiline fields I think.

Here is an exemple:

from PyPDFForm import PdfWrapper

filled = PdfWrapper("report.pdf",).fill(
    {
        "301 What Happened": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris congue, lorem sit amet venenatis lacinia, quam tortor pharetra ante, id facilisis neque velit ac tellus. Nam tincidunt felis quis eros malesuada, ac congue elit consequat. Ut eget porttitor augue. Integer ullamcorper lectus et est scelerisque, ac posuere mi tempor. Nunc vulputate vehicula bibendum. Aliquam erat volutpat. Morbi tortor."
    }
)

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

Input: report.pdf Output: filled.pdf

Result: image

plapointe6 avatar May 08 '24 14:05 plapointe6

So in other words paragraph field overflows vertically. Ok this is actually expected behavior. I’ll implement an auto adjusting mechanism no later than the end of this week and get back to you.

chinapandaman avatar May 08 '24 15:05 chinapandaman

Great ! Thanks a lot.

plapointe6 avatar May 08 '24 15:05 plapointe6

Hey, I just made a new bump. Turns out to be easier than I thought. Performance might be a bit concerning but I will get to that later. Give v1.4.24 a try and let me know if there are more issues.

chinapandaman avatar May 09 '24 03:05 chinapandaman

It works. Thanks !

I found that if I set the global_font_size, it overrides the new adaptative font behavior though. Is the default font size used by PdfWrapper come from the PDF configuration or it is embeded in the lib ?

plapointe6 avatar May 10 '24 14:05 plapointe6

When you set a font size, I assume you know what you are doing and know the risk of larger font size would potentially cause texts overflowing. So yes setting font size does overwrite the auto adjust behavior.

The default font size for paragraph field is set to 12 and embedded into the lib. I don't know how to extract that info out of a PDF. If you happen to know I'm all ears.

chinapandaman avatar May 10 '24 20:05 chinapandaman

Make sense.

No, I don't know a way to extract that info out of a PDF.

Maybe in the future, I will make a pull request to add an optional parameter "default_font_size" to override the embedded 12 while maintaining the automatic font adjustment.

But my issue is well resolved. Thanks for your help.

plapointe6 avatar May 13 '24 12:05 plapointe6

Hey man, I know this might be a bit late into the party but just want to throw this here if you still need it: https://chinapandaman.github.io/PyPDFForm/simple_fill/#adobe-mode-beta

It's still in beta and there are some hiccups with this messing up checkbox and radio button styles. But I tested your template and it should be good for at least text fields.

chinapandaman avatar Jun 15 '24 04:06 chinapandaman