Skip to content

Commit

Permalink
Fix existing root pages finding.
Browse files Browse the repository at this point in the history
  • Loading branch information
Li committed Feb 9, 2018
1 parent 7babd4c commit 6ae3725
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def _convert_caj(self, dest):
# generate catalog object
catalog_obj_no = fnd_unuse_no(obj_no, top_pages_obj_no)
obj_no.append(catalog_obj_no)
root_pages_obj_no = None
if multi_pages_obj_missed:
root_pages_obj_no = fnd_unuse_no(obj_no, top_pages_obj_no)
elif single_pages_obj_missed:
Expand All @@ -136,15 +137,16 @@ def _convert_caj(self, dest):
found = False
for pon in pages_obj_no:
tmp_addr = fnd(pdf, bytes("\r{0} 0 obj".format(pon), 'utf-8'))
pdf.seek(tmp_addr)
while True:
pdf.seek(tmp_addr)
[_str] = struct.unpack("6s", pdf.read(6))
if _str == b"Parent":
break
elif _str == b"endobj":
root_pages_obj_no = pon
found = True
break
tmp_addr = tmp_addr + 1
if found:
break
catalog = bytes("{0} 0 obj\r<</Type /Catalog\r/Pages {1} 0 R\r>>\rendobj\r".format(
Expand Down

0 comments on commit 6ae3725

Please sign in to comment.