当页面位于第一个标签定义之前时,Page.get_label() 会引发 IndexError
作者: AhmedKishki创建于 2026年9月25日更新于 2026年9月28日
标签fix developedhas test
Page.get_label() raises IndexError: list index out of range for a page that precedes the first entry of the document's /PageLabels number tree. Such a document is legal — /PageLabels need not cover page 0 — and the same call already returns '' when a document has no /PageLabels at all. So "no label applies to this page" is an answer this API already expresses; it just cannot be reached when the tree exists but starts later. In 1.28.2, the selection is pymupdf/utils.py:965; the same expression is on master in src/utils.py and src_classic/utils.py:
item = [x for x in labels if x[0] <= pgNo][-1]For a page before the first rule, the comprehension is empty and [-1] raises. The expression has no way to represent the case that exists.
内容来源: pymupdf/PyMuPDF