Atomically parse and understand complex PDF documents using claude-opus-4-6 (Anthropic).
Handles equations, graphs, algorithms, unique drawings, multi-column layouts, scanned pages,
and 100+ page documents without hallucination.
Designed to be dropped into local agent pipelines as a callable module.
What Makes This Work
Claude processes PDFs natively through Anthropic's document API. Each page is sent as a
base64-encoded PDF chunk (or rendered at 300 DPI in image mode) alongside a structured
JSON extraction prompt. The model simultaneously sees:
The rasterized visual content (charts, graphs, drawings, handwriting)
The underlying text layer (searchable text, equations, captions)
This dual perception eliminates the need for separate OCR, layout parsers, or equation
recognizers. The model returns fully structured JSON containing LaTeX equations, Markdown
tables, verbatim algorithm code, and semantic figure descriptions per page.
Features
Feature
Description
Native PDF API
Sends PDF bytes directly; Claude sees both text and visuals
Image mode
Renders pages at 300 DPI via PyMuPDF for maximum fidelity
LaTeX equations
Every equation extracted as proper LaTeX
Table extraction
Tables as Markdown and list-of-dicts JSON
Algorithm extraction
Pseudocode and code blocks verbatim with language detection
Figure description
Semantic descriptions of charts, plots, diagrams, drawings
SQLite caching
Pages are cached; re-runs skip already-parsed pages
Chunked processing
Handles 100+ page documents by splitting into chunks
Multiple output formats
JSON, Markdown, plain text
Agent interface
AgentPDFInterface class for programmatic use
Batch processing
Process entire directories of PDFs
Requirements
Python 3.10 or higher
An Anthropic API key with access to claude-opus-4-6
No GPU required; all inference runs through the Anthropic API
External System Dependencies
PyMuPDF (installed via pip) requires no external system libraries on most platforms.
On some Linux systems you may need:
sudo apt-get install -y libmupdf-dev
On macOS:
brew install mupdf
On Windows: PyMuPDF ships with pre-built wheels on PyPI; no additional steps needed.
1exportANTHROPIC_API_KEY="sk-ant-..."# Linux / macOS2setANTHROPIC_API_KEY=sk-ant-... # Windows CMD3$env:ANTHROPIC_API_KEY="sk-ant-..."# Windows PowerShell
Quick Start
Parse a PDF
python pdf_atomic_parser.py parse document.pdf
Outputs document_parsed.json in the current directory.
1from pdf_atomic_parser import AgentPDFInterface
23agent = AgentPDFInterface(model="opus")45# Full structured parse6result = agent.parse("paper.pdf")78# Just equations as list of dicts9equations = agent.get_equations("paper.pdf")10for eq in equations:11print(f"Page {eq['page']}: {eq['latex']}")1213# Just tables14tables = agent.get_tables("paper.pdf")1516# Semantic query17answer = agent.ask("paper.pdf","What datasets were used for evaluation?")18print(answer)
Usage Reference
Command Overview
Command
Purpose
parse <pdf>
Parse entire PDF to JSON/Markdown/text
atomic <pdf>
Full extraction to output directory (all formats)
extract-equations <pdf>
Extract LaTeX equations only
extract-tables <pdf>
Extract tables only
extract-algorithms <pdf>
Extract algorithms and code blocks only
extract-figures <pdf>
Extract figure descriptions only
query <pdf> "<question>"
Semantic question-answering over document
batch <dir>
Batch process all PDFs in a directory
estimate <pdf>
Estimate token count and cost before parsing
cache-stats
Show SQLite cache statistics
list-cache
List all cached documents
clear-cache <pdf>
Clear cached pages for a document
Global Options
Option
Default
Description
--model
opus
opus, sonnet, haiku, or full model string
--mode
native
native (PDF bytes) or image (300 DPI PNG per page)
--chunk-size
20
Number of pages per API call
--verbose
off
Enable debug logging
parse / atomic Options
Option
Default
Description
--output / -o
auto
Output file or directory path
--format / -f
json
json, markdown, or text
--pages
all
Page range, e.g. 1-50
Output Schema
Each parsed document returns a DocumentResult with:
title, authors, abstract, document_summary
page_results: list of PageResult per page
Each PageResult contains:
json
1{2"page_number":3,3"raw_text":"Full verbatim text...",4"summary":"This page describes...",5"section_headers":["Introduction","Related Work"],6"keywords":["transformer","attention","BERT"],7"equations":[8{9"index":0,10"latex":"\\mathcal{L} = -\\sum_{i} y_i \\log \\hat{y}_i",11"description":"Cross-entropy loss function",12"inline":false13}14],15"tables":[16{17"index":0,18"markdown":"| Model | Accuracy |\n|---|---|\n| BERT | 94.2 |",19"json_data":[{"Model":"BERT","Accuracy":"94.2"}],20"caption":"Table 1: Benchmark results"21}22],23"algorithms":[24{25"index":0,26"name":"Algorithm 1: Backpropagation",27"language":"pseudocode",28"code":"for each layer l from L to 1:\n ...",29"description":"Gradient descent update rule"30}31],32"figures":[33{34"index":0,35"figure_type":"line_chart",36"description":"Training loss over 100 epochs...",37"data_summary":"Y-axis: loss 0-2.0, X-axis: epoch 0-100...",38"caption":"Figure 2: Training curves"39}40]41}
Choosing a Mode
Scenario
Recommended Mode
Reason
Standard digital PDF
native (default)
Fastest, uses both text and visual layers
Scanned / photographed PDF
image
Text layer absent; vision handles everything
PDF with complex math
image
300 DPI render ensures equation clarity
Very large file (>32 MB)
image
Native API has 32 MB size limit per chunk
Cost-sensitive workflow
native
Fewer tokens consumed
Cost Estimate
Rough estimates per 100-page academic paper:
Model
Est. Tokens
Est. Cost
claude-opus-4-6
~120,000
~$3.50
claude-sonnet-4-6
~120,000
~$0.60
claude-haiku-4-5
~120,000
~$0.10
Use python pdf_atomic_parser.py estimate document.pdf for a per-document estimate.
Caching
Parsed pages are stored in ~/.cache/pdf_atomic_parser/.pdf_parser_cache.db.
Re-running on the same document skips already-parsed pages automatically.
The cache key is (document_SHA256, page_number, model, mode).
Project Structure
pdf-atomic-parser/
pdf_atomic_parser.py Main tool (single file, no splitting needed)
requirements.txt Python dependencies
README.md This file
model_card.yml Hugging Face model card
.gitignore
.gitattributes