Skip to content

Commit

Permalink
Bug fix pdf parse index out of range (#440)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?

fix a bug comes when parse some pdf file #436 

### Type of change

- [☑️ ] Bug Fix (non-breaking change which fixes an issue)
  • Loading branch information
Jiafan committed Apr 19, 2024
1 parent 1dada69 commit 39f1fea
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion deepdoc/parser/pdf_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,10 +830,13 @@ def _line_tag(self, bx, ZM):
pn = [bx["page_number"]]
top = bx["top"] - self.page_cum_height[pn[0] - 1]
bott = bx["bottom"] - self.page_cum_height[pn[0] - 1]
if pn[-1] - 1 >= len(self.page_images): return ""
page_images_cnt = len(self.page_images)
if pn[-1] - 1 >= page_images_cnt: return ""
while bott * ZM > self.page_images[pn[-1] - 1].size[1]:
bott -= self.page_images[pn[-1] - 1].size[1] / ZM
pn.append(pn[-1] + 1)
if pn[-1] - 1 >= page_images_cnt:
return ""

return "@@{}\t{:.1f}\t{:.1f}\t{:.1f}\t{:.1f}##" \
.format("-".join([str(p) for p in pn]),
Expand Down

0 comments on commit 39f1fea

Please sign in to comment.