Lightweight PDF parser with layout, tables, formulas and bounding boxes
📄 Papero PDF Text Extractor: A Lightweight Parser for Layout, Tables, and Formulas
papero-pdf-text-extractor is a high-performance, open-source API designed to extract text from PDFs without relying on heavyweight cumbersome software stacks. It transforms complex PDFs into structured formats like Markdown, JSON, Word, and Excel, while meticulously preserving the reading order, mathematical formulas, tables, figures, and the exact coordinates of every element.
"The true value for RAG, search engines, and LLMs lies in recovering the document's structure—identifying column sequences, table boundaries, and formula locations."
By utilizing plain geometry, papero remains efficient enough to run quickly on a standard laptop CPU.
🚀 Core Capabilities
- 📖 Intelligent Reading Order: Handles multi-column layouts (2 or 3 columns) by reading them sequentially. It automatically filters out noise like page numbers, footers, headers, and recurring logos.
- ▦ Robust Table Extraction: Supports borderless, ruled, and LaTeX
booktabsstyles. It correctly identifies rows and columns, even when cells span multiple lines. - Mathematical Formulas: Recognizes complex math (indices, exponents, roots, fractions) and converts them into LaTeX.
- Example: becomes
\frac{5}{12}and becomes\sqrt{2}. - It also provides a cropped image of the original formula.
- Example: becomes
- 📍 Precise Bounding Boxes: Every extracted block includes its exact position. This is critical for citing sources in RAG applications or performing visual crops.
- 🖼 Figure & Chart Handling: Extracts images and vector graphics as PNGs, ensuring that legends, axis labels, and captions remain grouped together.
- 📝 High-Fidelity Word Export: Maintains the original visual essence—including columns, indentation, font weights, and line spacing—so the
.docxoutput mirrors the source PDF.
Additional Features:
- Glyph Correction: Fixes LaTeX-style separate glyphs (e.g., converting
Computa¸ca˜oComputação). - Noise Reduction: Strips invisible white text often used by form generators.
- OCR Integration: Automatically processes scanned pages.
- Multi-format Support: Uses Apache Tika to handle
.docx,.pptx,.xlsx,.epub, and.html.
🛠️ Getting Started
Quick Installation
pip install papero-extract
Basic Usage
from papero_extract import extract
# Extract a PDF and convert to Markdown
doc = extract("paper.pdf")
print(doc.to_markdown())
Alternatively, you can use the browser app to upload a PDF and export it directly.
Advanced Python API
from papero_extract import extract, extract_text
# Extract with image cropping enabled
doc = extract("paper.pdf", images=True)
data = doc.to_dict() # Returns full JSON structure
# Handle math in different formats
# Example: "Se $\operatorname{tg} x - \operatorname{cotg} x = 1$, então…"
print(doc.to_markdown(math="latex"))
# Process non-PDF files via Tika
print(extract("slides.pptx").to_markdown())
# Fastest method: plain text only
text = extract_text("contract.pdf").text
Configuration Options
| Option | Default | Description |
|---|---|---|
pages | all | Specify pages (e.g., "1-3,5,10-") |
images | False | Crop tables, formulas, and figures to PNG |
tables / formulas | True | Toggle detection on/off |
ocr | "auto" | "auto" (scans only), "force", or "off" |
ocr_language | "por+eng" | Tesseract language codes |
tika | True | If False, runs layout engine without Java |
workers | 1 | Number of processes for large files |
💻 Command Line Interface (CLI)
| Command | Purpose |
|---|---|
papero-extract extract paper.pdf -o paper.md --images | Markdown + image folder |
papero-extract extract paper.pdf -o paper.json | JSON output |
papero-extract extract paper.pdf -f csv -o tables.csv | Extract tables only |
papero-extract extract paper.pdf -p 1-5 -f html | First 5 pages to HTML |
papero-extract extract paper.pdf --math latex -o p.md | Math as $ ... $ |
papero-extract extract paper.pdf --fast | Clean text only |
papero-extract batch ./documents -o ./dataset | Process folder for RAG |
papero-extract serve --port 8000 | Start API and Browser App |
📊 Batch Processing & Fidelity Reports
When processing a folder for RAG, papero generates a structured dataset:
Dataset Structure:
documents/: Contains one.mdand one.jsonper PDF.chunks.jsonl: Text split by headings; tables are kept intact.manifest.json: Metadata per document (pages, tables, fidelity scores).fidelity/:report.json: Detailed issue logs.summary.html: Browser-viewable summary.problematic/: JSON files for documents with warnings.
Chunk Example:
{
"id": "paper.pdf#12",
"type": "table",
"headings": ["4 Results"],
"pages": [6, 6],
"blocks": ["p6-b3"],
"text": "Table 2: Accuracy per model.\n\n | Model | Top-1 | …"
}
Fidelity Signals
The system checks the output against the source PDF to highlight areas for review:
- Text: Are all words read by PDFium present in the output?
- Reading Order: Is any block read out of sequence (e.g., reading a lower block before an upper one in the same column)?
- Tables: Does every "Table N" caption have a corresponding grid?
- Figures: Does every "Figure N" caption have a corresponding image?
- Formulas: Does every formula have LaTeX and mapped glyphs?
The Browser App visualizes this via a "Compare" tab, highlighting missing text or failed checks directly on the PDF page.