summaryrefslogtreecommitdiff
path: root/testing/tools/fixup_pdf_template.py
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-06-26 12:23:51 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-06-26 20:28:24 +0000
commitbdb330ee4d4d9d6fafc6bc84d4fa28c045eda936 (patch)
tree42c67b6f3027cb85a7b70d9171c641f3067bbe12 /testing/tools/fixup_pdf_template.py
parentcbe6d1662e2b76a343702fc77334f6e68b854427 (diff)
downloadpdfium-bdb330ee4d4d9d6fafc6bc84d4fa28c045eda936.tar.xz
Fix the Size trailer entry in hand written PDFs.
Change-Id: Ib84cc570c2ffaf9fdd49d32bc12c7e6197e130c1 Reviewed-on: https://pdfium-review.googlesource.com/6850 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'testing/tools/fixup_pdf_template.py')
-rwxr-xr-xtesting/tools/fixup_pdf_template.py15
1 files changed, 12 insertions, 3 deletions
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)