diff --git a/CHANGES.rst b/CHANGES.rst index 29dc9cb..9884655 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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 ----- diff --git a/src/img2pdf.py b/src/img2pdf.py index 91348af..8b7a1fb 100755 --- a/src/img2pdf.py +++ b/src/img2pdf.py @@ -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(