Skip to content

bug: IndexError for Page.get_links after Page.clip_to_rect #4942

@mahlzahn

Description

@mahlzahn

Description of the bug

On some sample PDF files, I get following IndexError, trying to get their links:

/usr/lib/python3.14/site-packages/pymupdf/__init__.py in ?(page)
  11835         links = []
  11836         while ln:
  11837             nl = utils.getLinkDict(ln, page.parent)
  11838             links.append(nl)
> 11839             ln = ln.next
  11840         if links != [] and page.parent.is_pdf:
  11841             linkxrefs = [x for x in
  11842                     #page.annot_xrefs()

/usr/lib/python3.14/site-packages/pymupdf/__init__.py in ?(self)
   8588             if self.xref > 0:  # prev link has an xref
   8589                 link_xrefs = [x[0] for x in self.parent.annot_xrefs() if x[1] == mupdf.PDF_ANNOT_LINK]
   8590                 link_ids = [x[2] for x in self.parent.annot_xrefs() if x[1] == mupdf.PDF_ANNOT_LINK]
   8591                 idx = link_xrefs.index(self.xref)
-> 8592                 val.xref = link_xrefs[idx + 1]
   8593                 val.id = link_ids[idx + 1]
   8594             else:
   8595                 val.xref = 0

IndexError: list index out of range

How to reproduce the bug

  1. Get sample file from here: https://github.com/ArtifexSoftware/tests/blob/master/pdf/Transparency-DesignGuide.pdf
  2. Run following python code:
document = pymupdf.Document("Transparency-DesignGuide.pdf")
page = document[0]
page.clip_to_rect(page.cropbox)
page.get_links()

PyMuPDF version

1.27.1

Operating system

Linux

Python version

3.14

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions