From 5a1f0701a31600881de1a346d920d60900286008 Mon Sep 17 00:00:00 2001 From: josch Date: Fri, 13 Mar 2015 13:05:23 +0100 Subject: [PATCH] to allow non-ascii characters, encode strings as utf-16-be (big endian) and escape backslashes and parenthesis --- CHANGES.rst | 1 + src/img2pdf.py | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) 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(