ccnmtl / fdfgen

port of PDF fdfgen library for filling in PDF forms to Python
BSD 3-Clause "New" or "Revised" License
171 stars 35 forks source link

forge_fdf generates weird characters #9

Open lc-thomas opened 9 years ago

lc-thomas commented 9 years ago

Forge_fdf generates weird characters in keys and values of the data I give it. Since it changes the keys, the output pdf forms aren't modified.

When manually removing these characters, it works very well.

ss 2015-02-04 at 04 22 08

Characters as seen by notepad++ :

ss 2015-02-04 at 04 27 15

lc-thomas commented 9 years ago

Here's my little (and dirty) workaround :

def smart_encode_str(s): """Create a UTF-16 encoded PDF string literal for s.""" try: utf16 = s.encode('utf_16_be') except AttributeError: # ints and floats utf16 = str(s).encode('utf_16_be') safe = utf16.replace(b'\x00)', b'\x00)').replace(b'\x00(', b'\x00(').replace(b'\x00','') return b''.join((codecs.BOM_UTF16_BE, safe))[2:]

mpbunch commented 8 years ago

Seems to still be an issue: screen shot 2016-04-05 at 6 21 56 pm

screen shot 2016-04-05 at 6 30 52 pm

Is there a quick fix for this?

sontek commented 6 years ago

How does this look now that #16 was merged?