docling-project / docling-project/docling

extract_outline_from_pdfium raises AttributeError on pypdfium2 4.x

Open Beginner friendly
#4,160 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
66.4k
Forks
4.8k
Avg merge
2d 21h
Merged PRs (30d)
84

Description

### Bug

`extract_outline_from_pdfium()` in `docling/utils/pdf_outline.py` reads each bookmark
with `bm.get_title()` and `bm.get_dest()`. Those exist on pypdfium2 5, but on 4.30
`PdfDocument.get_toc()` yields a `PdfOutlineItem` namedtuple:

```python
PdfOutlineItem(level, title, is_closed, n_kids, page_index, view_mode, view_pos)
```

which has no such methods, so the call raises:

```
AttributeError: 'PdfOutlineItem' object has no attribute 'get_title'
```

`pyproject.toml` declares `pypdfium2>=4.30.0,!=4.30.1,<6.0.0`, so 4.x is a supported
range. On it, `PyPdfiumDocumentBackend.get_document_outline()` raises and the document
outline — the most authoritative heading-hierarchy signal — is unavailable.

The 4.30 namedtuple already carries what the 5 API reaches through the destination
object (`page_index`, `view_mode`, `view_pos`), so both shapes can be read.

### Steps to reproduce

```console
$ pip install 'pypdfium2==4.30.0'
```

```python
import pypdfium2 as pdfium
from docling.utils.pdf_outline import extract_outline_from_pdfium

# any PDF that has bookmarks
extract_outline_from_pdfium(pdfium.PdfDocument("manual.pdf"))
# AttributeError: 'PdfOutlineItem' object has no attribute 'get_title'
```

### Docling version

2.124.0

### Python version

3.13.15

Contributor guide

Open the contributing guide

Research direction

Start in docling/utils/pdf_outline.py at extract_outline_from_pdfium(), then check the pypdfium2 version range in pyproject.toml. Reproduce with pypdfium2==4.30.0 and a PDF with bookmarks, then verify the function handles both the 4.x PdfOutlineItem shape and the 5.x API without raising an AttributeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
82/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.