docling-project / docling-project/docling

PDF text extraction fails for subsetted/custom fonts — shows GLYPH placeholders

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

Description

When passing a PDF to `DocumentStream` using the `stream` parameter (raw bytes), some PDFs produce garbled text with `GLYPH` placeholders or letters that appear shifted (e.g., `7KH` instead of `THE`). This occurs only for PDFs that use subsetted fonts or custom encodings without a proper ToUnicode map. PDFs created from Word, LaTeX, or InDesign usually work fine, but certain exported PDFs or scanned PDFs fail.

**Steps to reproduce:**

```python
from docling import DocumentStream

# Using raw PDF bytes
with open("problematic.pdf", "rb") as f:
doc = f.read()

source = DocumentStream(name="problematic.pdf", stream=doc)
conv_result = self.doc_converter.convert(source)
```

**Observed behavior:**

* Output text contains `GLYPH` sequences.
* Letters may appear shifted, as if Caesar-ciphered.

**Expected behavior:**

* Extracted text should reflect the real content of the PDF.

**Environment:**

* Docling version: ` 2.40.0`
* Python version: `3.12.3`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.