1
0
Fork 0
forked from josch/img2pdf

to allow non-ascii characters, encode strings as utf-16-be (big endian) and escape backslashes and parenthesis

This commit is contained in:
josch 2015-03-13 13:05:23 +01:00
parent 317a0ee7f2
commit 5a1f0701a3
2 changed files with 10 additions and 1 deletions

View file

@ -7,6 +7,7 @@ CHANGES
- replace -x and -y option by combined option -s (or --pagesize) and use -S
for --subject
- correctly encode and escape non-ascii metadata
0.1.5
-----

View file

@ -518,7 +518,15 @@ def valid_size(string):
# is both, type str and type bytes (only the case in python2)
def pdf_embedded_string(string):
if type(string) is str and type(string) is not bytes:
string = string.encode("utf8")
# py3
pass
else:
# py2
string = string.decode("utf8")
string = b"\xfe\xff"+string.encode("utf-16-be")
string = string.replace(b'\\', b'\\\\')
string = string.replace(b'(', b'\\(')
string = string.replace(b')', b'\\)')
return string
parser = argparse.ArgumentParser(