MatthiasValvekens / pyHanko

pyHanko: sign and stamp PDF files
MIT License
460 stars 68 forks source link

CLI: Signing produces name from certificate without international characters #397

Closed msetina closed 4 months ago

msetina commented 4 months ago

Describe the bug Using simple addsign from example in documentation produces name texts without international characters

To Reproduce A certificate with international characters in name fields is needed

Screenshots image Example from code: image

Environment (please complete the following information):

Additional context

pdf_signer = PdfSigner(
            meta, signer=sgnr, stamp_style=stamp.QRStampStyle(
                # Let's include the URL in the stamp text as well
                stamp_text='Signed by: %(signer)s\nTime: %(ts)s\nURL: %(url)s',
                text_box_style=text.TextBoxStyle(
                    font=opentype.GlyphAccumulatorFactory('/usr/share/fonts/truetype/freefont/FreeMono.ttf')
                ),
            ),
        )
MatthiasValvekens commented 4 months ago

The fact that addsign on the CLI doesn't always correctly render text without a font configured isn't really a bug, but more of a natural limitation in the file format. The rub is that unless you supply a font file that has the glyphs you need so that pyHanko can subset/embed the font properly, you're going to have to rely on one of the "default" fonts that is available in most/all viewers. These default fonts (a) have limited character sets to begin with, and (b) can differ from viewer to viewer, so the result is unpredictable no matter what.

So, long story short, you need a font file set up in your config file, otherwise this kind of thing doesn't work.

(This is in the FAQ, by the way ;) https://pyhanko.readthedocs.io/en/latest/faq.html#i-want-to-put-unicode-text-in-my-signatures-but-i-m-only-seeing-blanks-what-gives )