logo
Kurashizu Blogwhere ideas flow
  • Home
  • News
  • Blog
  • About
  • Home
  • News
  • Blog
  • About

© 2026 Kurashizu. All rights reserved.

Admin·New Post·Service Status
Powered by Cloudflare·30.10.26
← Back to news

Lightweight PDF parser with layout, tables, formulas and bounding boxes

Original article
github.com|17 points|3 comments|by beatrizalmeidaf|Oct 1, 2026

📄 Papero PDF Text Extractor: A Lightweight Parser for Layout, Tables, and Formulas

CI

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 booktabs styles. It correctly identifies rows and columns, even when cells span multiple lines.
  • ∑\sum∑ Mathematical Formulas: Recognizes complex math (indices, exponents, roots, fractions) and converts them into LaTeX.
    • Example: 5/125/125/12 becomes \frac{5}{12} and 10210\sqrt{2}102​ becomes \sqrt{2}.
    • It also provides a cropped image of the original formula.
  • 📍 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 .docx output mirrors the source PDF.

Additional Features:

  • Glyph Correction: Fixes LaTeX-style separate glyphs (e.g., converting Computa¸ca˜o →\rightarrow→ Computaçã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

OptionDefaultDescription
pagesallSpecify pages (e.g., "1-3,5,10-")
imagesFalseCrop tables, formulas, and figures to PNG
tables / formulasTrueToggle detection on/off
ocr"auto""auto" (scans only), "force", or "off"
ocr_language"por+eng"Tesseract language codes
tikaTrueIf False, runs layout engine without Java
workers1Number of processes for large files

💻 Command Line Interface (CLI)

CommandPurpose
papero-extract extract paper.pdf -o paper.md --imagesMarkdown + image folder
papero-extract extract paper.pdf -o paper.jsonJSON output
papero-extract extract paper.pdf -f csv -o tables.csvExtract tables only
papero-extract extract paper.pdf -p 1-5 -f htmlFirst 5 pages to HTML
papero-extract extract paper.pdf --math latex -o p.mdMath as $ ... $
papero-extract extract paper.pdf --fastClean text only
papero-extract batch ./documents -o ./datasetProcess folder for RAG
papero-extract serve --port 8000Start API and Browser App

📊 Batch Processing & Fidelity Reports

When processing a folder for RAG, papero generates a structured dataset:

Dataset Structure:

  • documents/: Contains one .md and one .json per 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.