RAG & Documents
Which PDF parser should you use for RAG in Spanish? 6 libraries measured on invoices and two columns
Only PyMuPDF4LLM and Docling keep 100% of invoice rows on a single line; pypdf and PyMuPDF, 0%. Docling is the only one that removes page footers, at 471.7 ms per page.
- Date
- Oct 22, 2026
- Reading time
- 8 min
- Result
- 100% intact invoice rows with PyMuPDF4LLM and Docling • 0% with pypdf and PyMuPDF • from 2.1 to 471.7 ms per page
Translated from the Spanish original. The code, data and READMEs on GitHub are in Spanish.
For a RAG over Spanish invoices and tables, PyMuPDF4LLM and Docling are the only ones of the 6 parsers tested that keep 100% of rows (item, price and total) on a single line; pypdf and PyMuPDF, 0%. Docling is also the only one that removes page footers (the others leave 100% of them in the text), but it takes 471.7 ms per page vs 230.5 ms for PyMuPDF4LLM and 2.1 ms for PyMuPDF. None of them loses accents, ñ, ¿ ¡, « » or €. Measured on 22 October 2026 with 36 PDFs (60 pages) generated with their exact reference text.
The question “which PDF parser should I use for RAG?” comes up again and again in forums, issues and blogs, almost always with documents in English, a screenshot of one page or a benchmark from a vendor selling its own parser. Here is the measurement in Spanish, with corpus, code and outputs published.
Definitions
- PDF parser: the library that turns the PDF into text (or Markdown) before splitting it into chunks for RAG. Whatever the parser breaks, the retriever can no longer recover.
- Intact row: the item, unit price and total of an invoice line come out together, on the same line and in order. If they come out on separate lines, one chunk may end up with the item and another with the amount.
- Intact paragraph: the reference paragraph appears whole and continuous in the output (ignoring spaces, line breaks and Markdown markup).
- Leaked footer: the “Página N” (page N) footer appears in the output and ends up in the middle of the text being chunked.
Hypotheses
- Simple parsers (pypdf, PyMuPDF) lose table structure.
- Those that rebuild the layout (PyMuPDF4LLM, Docling) keep it, at the cost of time and memory.
- Spanish characters (accents, ñ, ¿ ¡, « », €) get lost or corrupted in some of them.
- Two columns confuse parsers that read line by line.
Setup
- Corpus: 36 digital PDFs generated with ReportLab and a fixed seed, with the exact text saved as the reference: 12 single-column reports, 12 two-column reports and 12 invoices with amounts in Spanish format (1.234,56 €); in 6 of them the items span several lines within the cell. Every page carries the footer “Página N”. 60 pages in total.
- Parsers (6): pypdf, pdfplumber, PyMuPDF (
get_text), PyMuPDF4LLM (to_markdown), MarkItDown and Docling, each with its simplest call and default configuration (Docling with automatic OCR and TableFormer in accurate mode). - Repetitions: 5 per parser, each in a fresh process and in interleaved order, after a warm-up pass. Time for the full corpus and peak process memory; import time measured separately.
- Machine: Apple M1 Max laptop with 64 GB, macOS 26.6.2, Python 3.12.4.
Results
Quality of the extracted text
| Parser | Intact rows (invoices) | Intact rows (long items) | Intact paragraphs (1 column) | Intact paragraphs (2 columns) | Leaked footers |
|---|---|---|---|---|---|
| Docling | 100% | 100% | 100% | 97.13% | 0% |
| PyMuPDF4LLM | 100% | 100% | 96.34% | 93.13% | 100% |
| pdfplumber | 74.16% | 48.32% | 96.34% | 20.75% | 100% |
| MarkItDown | 74.16% | 48.32% | 96.34% | 12.46% | 100% |
| PyMuPDF | 0% | 0% | 96.34% | 95.29% | 100% |
| pypdf | 0% | 0% | 96.34% | 95.29% | 100% |
All six keep 100% of Spanish special characters and 100% of the item, price and total cells on invoices with short items. The difference is in how they lay them out:
- pypdf and PyMuPDF put each cell on its own line: “Concepto”, “Cantidad”, “Precio unitario”… one under the other. All the data is there (100% of cells), but no row stays together.
- pdfplumber and MarkItDown keep the row on one line, but when the item spans two lines in the cell, the second half comes out on a separate line, with no amounts: 48.32% intact rows on those invoices. With two columns they interleave the lines of one column with the other: only 20.75% and 12.46% of paragraphs come out whole, and similarity to the original text drops to 46.79% and 43.09%.
- PyMuPDF4LLM and Docling return the invoices as Markdown tables with one row per line, including long items.
- The 96.34% for one column isn’t a reading failure: it’s the paragraph that crosses the page break, split by the “Página N” footer. Docling recognises it as a footer and removes it; the other five leave it in.
- Docling isn’t perfect with two columns either: in 5 of the 12 reports it reordered chunks of lines at the column break (97.13% intact paragraphs).
Time and memory (median of 5 repetitions)
| Parser | Full corpus (60 pages) | Per page | Import | Peak memory |
|---|---|---|---|---|
| PyMuPDF | 0.13 s | 2.1 ms | 0.97 s | 313 MB |
| pypdf | 0.25 s | 4.2 ms | 0.21 s | 89.7 MB |
| pdfplumber | 2.39 s | 39.8 ms | 0.15 s | 95.6 MB |
| MarkItDown | 3.17 s | 52.8 ms | 1.46 s | 193.3 MB |
| PyMuPDF4LLM | 13.83 s | 230.5 ms | 0.97 s | 712.4 MB |
| Docling | 28.3 s | 471.7 ms | 5.97 s | 1298.7 MB |
Spread is low: Docling’s time per page ranges from 466.3 to 484.8 ms across repetitions and PyMuPDF4LLM’s from 229.6 to 241 ms. All six produced identical output (same SHA-256 hash) across the 5 repetitions.
PyMuPDF is no longer light on memory. PyMuPDF 2.0 declares pymupdf-layout, onnxruntime and pymupdf4llm as dependencies, and import pymupdf loads them. Repeated in an environment where only PyMuPDF was installed, the peak was 317.9 MB (median), so it isn’t an effect of sharing an environment with the others.
What it means
- Hypotheses 1 and 2: they hold. With pypdf or PyMuPDF, an invoice chunked for RAG separates items and amounts; with PyMuPDF4LLM or Docling, each invoice line travels whole in the same chunk.
- Hypothesis 3: it doesn’t hold. On digital PDFs, none of them loses accents, ñ, ¿ ¡, « » or €. Spanish’s problem isn’t the characters, it’s the structure.
- Hypothesis 4: it half holds. Two columns only sink pdfplumber and MarkItDown; pypdf and PyMuPDF follow block order and hold up.
- Page footers are the silent failure. Five of six parsers drop “Página N” into the middle of paragraphs. If you don’t filter them, they pollute chunks and embeddings.
When to use each option
- Invoices, quotes or any PDF with tables: PyMuPDF4LLM. The same intact rows as Docling at less than half the time per page and with 712.4 MB vs 1298.7 MB. Add a header and footer filter.
- Documents where layout matters (footers, headers, several columns) and volume is moderate: Docling. It’s the only one that removes footers unaided; expect almost half a second per page on a laptop and 5.97 s of start-up.
- Single-column running text, high volume and no tables: PyMuPDF (2.1 ms per page) or pypdf (4.2 ms per page and 89.7 MB). Watch the licence: PyMuPDF and PyMuPDF4LLM are AGPL or commercial; pypdf is BSD.
- pdfplumber: for pulling tables with its table API, not with
extract_texton two-column documents. - MarkItDown: on PDF it behaves like pdfplumber in this corpus; its advantage is converting many formats (Word, Excel, HTML) with a single call, not PDF quality.
Limitations
- A synthetic corpus: 36 clean, digital PDFs generated with ReportLab. Scanned PDFs, real supplier invoices, borderless tables or merged cells may give different results. In exchange, the reference is exact and the corpus can be published.
- The phrases «con un coste de …» (“at a cost of …”) carry a duplicated € symbol due to a generator bug. It’s the same in the PDF and the reference, so it doesn’t change the comparison.
- Each parser was tested with its default configuration. pdfplumber has
extract_tables, PyMuPDF hasfind_tablesand Docling lets you turn off OCR or use TableFormer’s fast mode: these weren’t measured. - Paid parsers and cloud services (LlamaParse, Azure Document Intelligence, Unstructured via API) and vision models weren’t tested.
- The intact-row metric requires item, price and total on the same line. A parser that separates cells by another consistent criterion would score 0% even if a table-aware chunker could put them back together.
- A single Apple Silicon laptop with other apps open. Docling uses PyTorch and its time varies a lot with the available GPU; the figures are good for the order of magnitude.
How to reproduce it
Code, corpus, each parser’s outputs and raw results (times per document, memory per repetition and quality per PDF): yeswelab-laboratorio/parsers-pdf-rag-espanol-tablas on GitHub. It runs in under 10 minutes with no accounts or keys; Docling downloads its models from Hugging Face the first time.
Related
- How many more tokens does Spanish use than English?
- Structured outputs with real outputs: what JSON mistakes LLMs make
- Context engineering and context bloat in AI agents
Have a RAG that answers badly with your PDFs and don’t know whether the problem is the parser, the chunking or the model? Commission the experiment with your documents.