{"slug": "lightweight-pdf-parser-with-layout-tables-formulas-and-bounding-boxes", "title": "Lightweight PDF parser with layout, tables, formulas and bounding boxes", "summary": "Developer Beatriz Almeida released papero, an open-source PDF parser that extracts reading order, tables, formulas, figures and bounding boxes from PDFs using geometry alone, with no ML models and CPU-only execution. The tool installs via `pip install pdf-text-api`, runs in the browser, Python or as a REST API, and exports to Markdown, JSON, Word, Excel, HTML and CSV, with OCR for scanned pages and Apache Tika support for DOCX, PPTX, XLSX, EPUB and HTML. papero is aimed at RAG, search and LLM pipelines that need document structure rather than raw text.", "body_md": "PDF → Markdown · JSON · Word · Excel — with reading order, tables, formulas, figures and the position of every block.\n\n  CPU only. No ML models. Runs in your browser, in Python, or as an API.\n\n[**▶ Try it in your browser**](https://beatrizalmeidaf.github.io/papero-pdf-text-extractor/)\n   · \n  [**Quick start**](#quick-start)\n   · \n  **Benchmarks**\n\n<sub>30 seconds in the browser app: load a PDF, inspect any block, check tables and formulas, export to Word. Your PDF never leaves your machine. ([MP4](https://github.com/beatrizalmeidaf/papero-pdf-text-extractor/blob/main/web/assets/demo.mp4))</sub>\n\nGetting the *text* out of a PDF is easy. Getting its **structure** back — which column comes first, which lines are a table, where the formula is — is what makes the output usable for RAG, search and LLMs. papero does that with plain geometry, so it stays fast on a laptop CPU.\n\n| **📖 Reading order** Two- and three-column papers read column by column. Headers, footers, page numbers and repeated logos are set aside. | **▦ Real tables** Ruled, borderless and LaTeX *booktabs* tables come back as rows and columns — multi-line cells included. Export to CSV or Excel. | **∑ Formulas** Superscripts, subscripts and math symbols become LaTeX ( `E = mc^{2}` ), plus a cropped image of the formula. | \n| **📍 Position of everything** Every block has a bounding box — cite the exact spot in a RAG answer, draw over the page, or crop it. | **🖼 Figures & charts** Images and vector charts are cropped to PNG, with their caption, axis labels and legend kept together. | **📝 Back to Word** Alignment, indents, line spacing, bold runs and fonts are kept, so a `.docx` export looks like the original page. | \n\nAlso: accents drawn as separate glyphs in LaTeX PDFs (`Computa¸ca˜o` → `Computação`), invisible white text used by form generators is dropped, scanned pages go through OCR, and DOCX/PPTX/XLSX/EPUB/HTML are read through Apache Tika.\n\n```\npip install pdf-text-api\npython\nfrom pdf_text_api import extract\n\ndoc = extract(\"paper.pdf\")\nprint(doc.to_markdown())\n```\n\nOr skip the install: **[open the browser app](https://beatrizalmeidaf.github.io/papero-pdf-text-extractor/)**, drop a PDF, export to the format you need.\n\n## **More Python** — tables, formulas, positions, images, options\n\n``` python\nfrom pdf_text_api import extract, extract_text\n\ndoc = extract(\"paper.pdf\", images=True)\n\ndoc.tables[0].rows  # [[\"Model\", \"Accuracy\"], [\"Base\", \"0.81\"], ...]\ndoc.formulas[0].latex  # \"E = mc^{2}\"\ndoc.figures[0].image.data  # PNG bytes\n\nfor block in doc.pages[0].blocks:  # reading order, with positions\n    print(block.type, block.bbox, block.text[:60])\n\ndoc.to_html()  # keeps alignment and indents\ndoc.to_dict()  # the full JSON\n\nextract(\"slides.pptx\").to_markdown()  # any format Apache Tika reads\nextract_text(\"contract.pdf\").text  # fastest: clean text only\n```\n\n| Option | Default |  | \n|---|---|---|\n| `pages` | all | `\"1-3,5,10-\"` | \n| `images` | `False` | crop figures, tables and formulas to PNG | \n| `tables` /`formulas` | `True` | detection on/off | \n| `ocr` | `\"auto\"` | `\"auto\"` (scanned pages only),`\"force\"` ,`\"off\"` | \n| `ocr_language` | `\"por+eng\"` | Tesseract languages | \n| `tika` | `True` | `False` runs the layout engine alone (no Java) | \n| `workers` | `1` | processes for long documents | \n\n## **CLI**\n\n```\npdf-text-api extract paper.pdf -o paper.md --images   # Markdown + images/ folder\npdf-text-api extract paper.pdf -o paper.json          # format from the extension\npdf-text-api extract paper.pdf -f csv -o tables.csv   # tables only\npdf-text-api extract paper.pdf -p 1-5 -f html\npdf-text-api extract paper.pdf --fast                 # clean text only\npdf-text-api serve --port 8000                        # API + browser app\n```\n\n## **REST API & Docker**\n\n```\ndocker compose up        # API + Apache Tika + Tesseract + browser app on :8000\ncurl -F \"file=@paper.pdf\" \"localhost:8000/v1/extract?format=markdown\"\ncurl -F \"file=@paper.pdf\" \"localhost:8000/v1/extract?format=zip&images=true\" -o paper.zip\ncurl -F \"file=@paper.pdf\" \"localhost:8000/v1/extract?per_page=true\"     # blocks + positions\n```\n\nOne endpoint, `POST /v1/extract`; interactive docs at `/docs`.\n\n| Parameter | Default |  | \n|---|---|---|\n| `mode` | `structured` | `structured` (layout + Tika) or`fast` (text only) | \n| `format` | `json` | `json` ,`markdown` ,`text` ,`html` ,`csv` ,`zip` | \n| `pages` | all | `1-3,5,10-` | \n| `per_page` | `false` | include pages, blocks and positions in the JSON | \n| `images` | `false` | crop figures, tables and formulas | \n| `ocr` | `auto` | `auto` ,`force` ,`off` | \n\nConfiguration through environment variables — see [`.env.example`](https://github.com/beatrizalmeidaf/papero-pdf-text-extractor/blob/main/.env.example).\n\nEvery block knows what it is and where it was:\n\n```\n{\n  \"type\": \"table\",\n  \"bbox\": [56.7, 294.8, 481.9, 374.2],\n  \"rows\": [[\"Model\", \"Accuracy\"], [\"Base\", \"0.81\"]],\n  \"caption\": \"Table 1: Comparison between models.\"\n}\n```\n\n| Output | Python · CLI · API | Browser app | \n|---|---|---|\n| Markdown, plain text, JSON | ✓ | ✓ | \n| HTML (keeps alignment and indents) | ✓ | ✓ | \n| CSV of the tables, ZIP with images | ✓ | ✓ | \n| Word `.docx` that keeps the page's look | — | ✓ | \n| Excel `.xlsx` , one sheet per table | — | ✓ | \n\n## **Full JSON schema and block types**\n\n```\n{\n  \"schema\": \"pdf-text-api/document@1\",\n  \"engine\": \"tika+pdfium\",\n  \"page_count\": 12,\n  \"metadata\": { \"title\": \"...\", \"author\": \"...\", \"language\": \"en\" },\n  \"pages\": [{\n    \"number\": 1, \"width\": 595.3, \"height\": 841.9,\n    \"blocks\": [{\n      \"id\": \"p1-b4\", \"type\": \"paragraph\", \"bbox\": [74.0, 217.0, 522.0, 275.0],\n      \"text\": \"Atestamos que a estudante ...\",\n      \"style\": { \"pt\": 11.0, \"font\": \"Arial\", \"bold\": false },\n      \"format\": { \"align\": \"justify\", \"first_line\": 42.7, \"line_spacing\": 1.8 },\n      \"runs\": [{ \"text\": \"FULANA DE TAL\", \"bold\": true, \"italic\": false, \"script\": null }]\n    }]\n  }]\n}\n```\n\nBlock types: `heading` (with `level`), `paragraph`, `list_item` (with `marker`), `table` (with `rows`), `figure`, `formula` (with `latex`), `caption`, `code`, and — kept apart from the text — `header`, `footer`, `page_number`. Bounding boxes are `[x0, y0, x1, y1]` in points, origin at the top-left of the page.\n\nDense arXiv papers (multi-column, formulas, tables, figures) on one laptop CPU, no GPU. `papero · fast` returns clean text; `papero · structured` also rebuilds reading order, tables, formulas and figures — **0 failures on 54 papers, 39 ms per page (median)**. Reproduce with [`benchmarks/`](https://github.com/beatrizalmeidaf/papero-pdf-text-extractor/blob/main/benchmarks).\n\n|  | papero | PyMuPDF | pdfplumber | pypdf | Docling | Marker | \n|---|---|---|---|---|---|---|\n| License | MIT | AGPL | MIT | BSD | MIT | GPL | \n| Needs ML models / PyTorch | no | no | no | no | yes | yes | \n| Multi-column reading order | ✓ | partial | — | — | ✓ | ✓ | \n| Structured tables | ✓ | ✓ | ✓ | — | ✓ | ✓ | \n| Formulas | LaTeX from glyphs + image | — | — | — | ✓ | ✓ | \n| Bounding boxes | ✓ | ✓ | ✓ | — | ✓ | ✓ | \n| DOCX / PPTX / XLSX / EPUB | ✓ | partial | — | — | ✓ | partial | \n| Runs entirely in the browser | ✓ | — | — | — | — | — | \n\nML-based tools still win on very irregular layouts and complex math (stacked fractions, matrices) — papero gives you the formula as approximate LaTeX **and** as an image so nothing is lost.\n\nTwo engines run on the same file **at the same time**:\n\n- **A layout engine on PDFium** reads every glyph with its position, font and size, plus every rule and image, and rebuilds columns, tables, formulas, lists and figures with a column-aware XY-cut.\n- **Apache Tika** adds metadata, tagged-PDF headings, OCR (Tesseract) and every non-PDF format.\n\nThe browser app runs the same algorithm ported to JavaScript on pdf.js, and CI checks block by block that both engines agree.\n\n## **Limitations**\n\n- **Math:** LaTeX is rebuilt from glyphs — stacked fractions, matrices and big radicals come out linear (the cropped image is always there).\n- **Borderless tables** with very narrow gaps between columns can read as text.\n- **Scanned PDFs** need OCR, which runs on the server path (Tesseract is in the Docker image).\n- **Word/Excel export** is in the browser app for now.\n\n## **Development**\n\n```\ngit clone https://github.com/beatrizalmeidaf/papero-pdf-text-extractor.git && cd pdf-text-extractor\npip install -e \".[dev]\"\npytest -q                                   # includes real-world regressions\nruff check src tests && ruff format --check src tests\nnpm install --prefix tests/js && python tests/js/expected.py tests/js/out && node tests/js/parity.mjs tests/js/out\npython -m http.server -d web                # browser app at http://localhost:8000\n```\n\n`src/pdf_text_api/` is the Python engine, API and CLI · `web/` is the browser app (GitHub Pages) · `tests/js/` checks the two engines agree · `benchmarks/` downloads the dataset and draws the chart.\n\nFound a PDF papero gets wrong? **That's the most useful issue you can open** — attach the file (or a page of it) and say what you expected. Reading order, tables, formulas, encoding, OCR and browser/server differences are all fair game.\n\nIf papero saves you time, **a ⭐ helps other people find it.**\n\n**Keywords:** PDF to Markdown · PDF to JSON · PDF to Word · PDF to Excel · PDF table extraction · PDF parser · document parsing · layout analysis · reading order · multi-column PDF · formula extraction · LaTeX · bounding boxes · OCR · Apache Tika · PDFium · pdf.js · RAG preprocessing · LLM document loader · Docling alternative · PyMuPDF alternative · converter PDF para Markdown, Word e Excel · extrair tabelas de PDF · extrair texto de PDF mantendo a formatação · OCR de PDF escaneado\n\n<sub>MIT © Beatriz Almeida · package and imports keep the name `pdf-text-api` / `pdf_text_api` for compatibility.</sub>", "url": "https://wpnews.pro/news/lightweight-pdf-parser-with-layout-tables-formulas-and-bounding-boxes", "canonical_source": "https://github.com/beatrizalmeidaf/papero-pdf-text-extractor", "published_at": "2026-10-01 16:14:40+00:00", "updated_at": "2026-10-01 16:18:14.502295+00:00", "lang": "en", "topics": ["ai-infrastructure", "developer-tools", "ai-tools", "natural-language-processing"], "entities": ["papero", "Beatriz Almeida", "pdf-text-api", "Apache Tika", "Tesseract", "Docker"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/lightweight-pdf-parser-with-layout-tables-formulas-and-bounding-boxes", "markdown": "https://wpnews.pro/news/lightweight-pdf-parser-with-layout-tables-formulas-and-bounding-boxes.md", "text": "https://wpnews.pro/news/lightweight-pdf-parser-with-layout-tables-formulas-and-bounding-boxes.txt", "jsonld": "https://wpnews.pro/news/lightweight-pdf-parser-with-layout-tables-formulas-and-bounding-boxes.jsonld"}}