From ba06e7eeccb4e08c072f2402a2759c49281154ca Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 5 Oct 2012 22:06:38 +0200 Subject: [PATCH] Nicer whitespace in PDF objects. --- weasyprint/pdf.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/weasyprint/pdf.py b/weasyprint/pdf.py index d0f4a7ac36..0f8c816fae 100644 --- a/weasyprint/pdf.py +++ b/weasyprint/pdf.py @@ -200,10 +200,12 @@ def read_object(self, object_number): assert int(line[:-7]) == object_number # len(b' 0 obj\n') == 7 object_lines = [] for line in fileobj: - object_lines.append(line) if line == b'>>\n': assert next(fileobj) == b'endobj\n' + # No newline, we’ll add it when writing. + object_lines.append(b'>>') return b''.join(object_lines) + object_lines.append(line) def overwrite_object(self, object_number, byte_string): """Write the new content for an existing object at the end of the file. @@ -222,10 +224,10 @@ def extend_dict(self, dictionary, new_content): the << >> delimiters. """ - assert dictionary.byte_string.endswith(b'>>\n') + assert dictionary.byte_string.endswith(b'>>') self.overwrite_object( dictionary.object_number, - dictionary.byte_string[:-3] + new_content + b'\n>>\n') + dictionary.byte_string[:-2] + new_content + b'\n>>') def next_object_number(self): """Return the object number that would be used by write_new_object(). @@ -384,7 +386,8 @@ def write_pdf_metadata(document, fileobj): for bookmark in bookmarks: content = [pdf_format('<< /Title {0!P}\n', bookmark['label'])] content.append(pdf_format( - '/A << /Type /Action /S /GoTo /D [{0} /XYZ {1:f} {2:f} 0] >>', + '/A << /Type /Action /S /GoTo ' + '/D [{0} /XYZ {1:f} {2:f} 0] >>\n', *bookmark['target'])) if bookmark['Count']: content.append(pdf_format('/Count {0}\n', bookmark['Count']))