Skip to content

Commit

Permalink
Fix the numbering of catalog object to avoid conflict.
Browse files Browse the repository at this point in the history
  • Loading branch information
Li committed Dec 20, 2017
1 parent abb597b commit 70bbde4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,14 @@ def _convert_caj(self, dest):
[ind] = struct.unpack(str(length) + "s", pdf.read(length))
inds.append(int(ind))
pages_obj_no = min(inds)
catalog = bytes("1 0 obj\r<</Type /Catalog\r/Pages {0} 0 R\r>>\rendobj\r".format(pages_obj_no), "utf-8")
catalog_obj_no = -1
for i in range(9999):
if fnd(pdf, bytes("\r{0} 0 obj".format(i + 1), "utf-8")) == -1 and i + 1 != pages_obj_no:
catalog_obj_no = i + 1
break
if catalog_obj_no == -1:
raise SystemExit("Error on PDF objects numbering.")
catalog = bytes("{0} 0 obj\r<</Type /Catalog\r/Pages {1} 0 R\r>>\rendobj\r".format(catalog_obj_no, pages_obj_no), "utf-8")
pdf_data += catalog
with open("pdf.tmp", 'wb') as f:
f.write(pdf_data)
Expand Down

0 comments on commit 70bbde4

Please sign in to comment.