From bdb330ee4d4d9d6fafc6bc84d4fa28c045eda936 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Mon, 26 Jun 2017 12:23:51 -0700 Subject: Fix the Size trailer entry in hand written PDFs. Change-Id: Ib84cc570c2ffaf9fdd49d32bc12c7e6197e130c1 Reviewed-on: https://pdfium-review.googlesource.com/6850 Commit-Queue: Lei Zhang Reviewed-by: Henrique Nakashima Reviewed-by: dsinclair --- testing/tools/fixup_pdf_template.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'testing/tools/fixup_pdf_template.py') diff --git a/testing/tools/fixup_pdf_template.py b/testing/tools/fixup_pdf_template.py index 80a712f6e8..10ca241242 100755 --- a/testing/tools/fixup_pdf_template.py +++ b/testing/tools/fixup_pdf_template.py @@ -10,8 +10,10 @@ script replaces {{name}}-style variables in the input with calculated results {{header}} - expands to the header comment required for PDF files. {{xref}} - expands to a generated xref table, noting the offset. + {{trailer}} - expands to a standard trailer with "1 0 R" as the /Root. {{startxref} - expands to a startxref directive followed by correct offset. - {{object x y}} - expands to |x y obj| declaration, noting the offset.""" + {{object x y}} - expands to |x y obj| declaration, noting the offset. +""" import optparse import os @@ -19,15 +21,19 @@ import re import sys class TemplateProcessor: - HEADER_TOKEN = '{{header}}' + HEADER_TOKEN = '{{header}}' HEADER_REPLACEMENT = '%PDF-1.7\n%\xa0\xf2\xa4\xf4' XREF_TOKEN = '{{xref}}' XREF_REPLACEMENT = 'xref\n%d %d\n' - # XREF rows must be exactly 20 bytes - space required. XREF_REPLACEMENT_N = '%010d %05d n \n' XREF_REPLACEMENT_F = '0000000000 65535 f \n' + # XREF rows must be exactly 20 bytes - space required. + assert(len(XREF_REPLACEMENT_F) == 20) + + TRAILER_TOKEN = '{{trailer}}' + TRAILER_REPLACEMENT = 'trailer<< /Root 1 0 R /Size %d >>' STARTXREF_TOKEN= '{{startxref}}' STARTXREF_REPLACEMENT = 'startxref\n%d' @@ -60,6 +66,9 @@ class TemplateProcessor: if self.XREF_TOKEN in line: self.xref_offset = self.offset line = self.generate_xref_table() + if self.TRAILER_TOKEN in line: + replacement = self.TRAILER_REPLACEMENT % (self.max_object_number + 1) + line = line.replace(self.TRAILER_TOKEN, replacement) if self.STARTXREF_TOKEN in line: replacement = self.STARTXREF_REPLACEMENT % self.xref_offset line = line.replace(self.STARTXREF_TOKEN, replacement) -- cgit v1.2.3