PDF Parsing API

Parse PDFs to structured JSON on your own machine, with pdftotext by default or Docling or LiteParse, and no API key or cost. For scanned pages, add an AI model (Gemini, Claude, OpenAI, Ollama). The output has the same shape as for Office files. Converting back? See PDF to Word and PDF to PowerPoint.

A PDF Does Not Store Structure

A PDF records where to draw each character on a page. It has no "heading", "paragraph" or "table cell". The structure has to be worked out from the layout: large bold text at the top of a page is a heading, aligned columns of text are a table, and reading order runs left to right, then top to bottom.

AILANG Parse does this with the PDF reader you choose, a local one by default or an AI model. It returns the same kinds of block as for DOCX, XLSX and PPTX, so your code handles every format the same way.

If the PDF was made from a DOCX and you still have the DOCX, parse that. You get the track changes, comments, merged cells and metadata that the PDF lost. See why parsing the DOCX beats parsing the PDF.

How It Works

With the AI backend, AILANG Parse sends the PDF to the AI provider you choose and asks for the content in a fixed structure. A long PDF is sent one page per request, so the model reads each page once and a long document costs no more per page than a short one. It checks the reply and converts it into blocks. You get the same blocks (headings, text, tables, images) whichever provider read the PDF.

Switch providers with one flag. Your code and the output format stay the same.

# Gemini (fastest, most cost-effective)
docparse document.pdf --pdf-backend ai --ai gemini-3.5-flash-lite

# Claude
docparse document.pdf --pdf-backend ai --ai claude-sonnet-4-5-20250514

# Ollama (fully local)
docparse document.pdf --pdf-backend ai --ai ollama/llama3.2-vision

AI Providers

Gemini

Best for high volumes. gemini-3.5-flash-lite has the fastest responses and the lowest cost per page. Use a larger Gemini model for documents with dense tables or several columns.

Claude

Strong on documents where context matters. claude-sonnet-4-5-20250514 does well on complex layouts and academic papers.

OpenAI

A good general choice. gpt-4o handles standard business documents well. Use it when your team already has an OpenAI API key and wants one provider.

Ollama (Local)

Runs entirely on your machine, so no data leaves it. Use any model that can read images, such as llama3.2-vision or llava. Suited to sensitive documents, networks with no internet access, and development at no cost.

Local Backends, No AI

A backend is the PDF reader AILANG Parse uses. The CLI reads PDFs on your machine unless you ask for AI. pdftotext is the default: a PDF that contains real text (not a scan) parses with no API key, no cost and no network call, and the same file always gives the same result. There are four local backends:

pdftotext default

Plain text with the page layout kept, from poppler’s pdftotext -layout. It returns the most complete text of any backend, and it is instant, free and offline, with no Python packages. The reliable choice for PDFs that contain real text, such as contracts, reports and invoices. It finds no text in a scanned or image-only PDF.

poppler structure, no installs

The same poppler tools as pdftotext, used to recover structure: headings, bulleted and numbered lists, tables from aligned columns, paragraphs rejoined across line breaks, bold and links kept, and the page header, footer and page numbers separated from the body. Two-column pages are read one column at a time. Headings come from the PDF’s own outline when it has one, and otherwise from font size, weight and section numbering, so a paper’s numbered headings set at body size are still found. Offline, the same result every run, and no Python packages. Use it for reports and research papers, and when converting a PDF back into a Word document.

Docling structural

IBM Docling analyses the page layout on your machine, with table detection and reading order. It finds the most headings of any backend on research papers, and it reads scans. A layout model takes seconds per paper, not a fraction of one: see the comparison. Free, MIT-licensed, no API key.

LiteParse fastest

LiteParse from run-llama extracts text with its position on the page, without a layout model. Headings are detected from font size alone, which suits documents whose headings are visibly larger than the body. Best for search indexing, or anywhere plain text is what you need.

Docling and LiteParse are Python packages that AILANG Parse runs for you. You choose the backend on each call, so there is no global setting to keep track of.

Install

The default pdftotext backend and the poppler backend need only poppler (brew install poppler / apt install poppler-utils), which most systems already have. The ai backend needs nothing installed. docling and liteparse need their Python package installed in the Python environment your CLI uses:

# Docling (see docling-project/docling for the full install matrix)
uv pip install docling

# LiteParse (see run-llama/liteparse)
uv pip install liteparse

# Or both
uv pip install docling liteparse

There is no service to start. Each one runs when you pass --pdf-backend docling or --pdf-backend liteparse. If the package is not installed, the parse fails with a NonZeroExit error that includes Python’s ImportError message.

Usage

# pdftotext — default, deterministic, no API key, most complete text
docparse paper.pdf

# poppler — headings, lists, tables, header/footer; same poppler, no installs
docparse report.pdf --pdf-backend poppler

# PDF back to Word, styled by your own template
docparse report.pdf --pdf-backend poppler --convert report.docx \
  --reference-doc house-style.docx

# AI — opt-in only; scanned/image-only PDFs escalate to local docling by default
docparse scan.pdf --pdf-backend ai --ai gemini-3.5-flash-lite

# Docling — local, structural, ~5× faster than Gemini
docparse paper.pdf --pdf-backend docling

# LiteParse — local, font-size heading inference
docparse paper.pdf --pdf-backend liteparse

Converting a PDF back into a Word document or a deck in your own template? PDF to Word and PDF to PowerPoint have examples you can open and say which backend to pick.

Every backend returns the same kinds of block, so your code does not change when you switch. With any backend other than ai, no API key is needed and no network call is made.

Which Backend to Pick

You haveUseWhy
A PDF that contains real text, and you want all of it (the common case)pdftotext (default)The most complete text; the same result every run; instant; free; offline; no Python packages.
Scanned PDFs, handwriting, pages that mix text and imagesdocling (chosen automatically for scans), or ai (Gemini / Claude / Ollama)Both read content that is not stored as text. pdftotext, poppler and liteparse cannot read scans.
A report or research paper, and you want its headings, lists and tablespopplerStructure in about a second per paper; reads two-column pages; the same result every run; free; offline; no Python packages.
The same, and you want the most headings found, or a layout model’s table detectiondoclingFinds the most headings; reads scans; free; offline. Takes several times longer than poppler.
Search indexing where headings detected from font size are enoughliteparseFast; simple heading detection; free; offline.

How the Backends Compare on Research Papers

Research papers are a hard case: two columns, numbered headings set at body size or in small capitals, formulas and figures in the reading order. We parse the published PDF of 12 arXiv papers with each backend and compare the headings it returns with the section headings in the paper’s LaTeX source.

BackendHow it reads the pageHeadings foundReported headings that are realTime per paper
pdftotextText only (the default)0%—0.5 s
popplerRules over the PDF’s own text and fonts84%71%1.0 s
doclingLayout model on your machine93%74%11 s
liteparseText positions and font size9%12%0.6 s
aiAI model, one request per page90%60%83 s

12 arXiv papers, 200 section headings taken from each paper’s LaTeX source. Measured 16 November 2026 on AILANG Parse 0.57.1, from the command line on one laptop. The ai row used gemini-3.5-flash-lite, measured 12 November 2026 on 0.57.0; a model’s answers vary from run to run. The source is not an exact answer key: “Abstract” and “References” are real headings it often does not name, and they count against the fourth column. Read the rows against each other. Run it yourself.

poppler finds 84% of the headings in 1.0 s a paper with no model at all. docling finds 93% and takes 11 s. The ai backend finds 90% and takes 83 s, because a model reads each page. pdftotext returns text only, so it reports no headings.

What Gets Extracted

Headings & Text

The AI tells headings from body text by font size, weight and position. They are returned as heading blocks, with a level, and text blocks.

Tables

Data laid out in aligned columns is returned as a table with headers and rows. The AI also follows a table that continues across a page break.

Images & Figures

Images are returned with their captions and alt text. The AI describes what each figure shows, for search indexing or accessibility.

Same Output Everywhere

Whichever AI provider you use, the output is the same set of blocks: heading, text, table, image. Your code does not change when you switch providers.

Highlights & Comments

A reviewed PDF holds more than its text: the highlights, sticky notes and typed comments a reader left on it. A PDF stores these as annotations (/Annots), separately from the text. Extract the text alone and every review comment is missing.

AILANG Parse reads the annotations with every backend, including the default pdftotext. Each one is returned as a comment block, in the same shape as DOCX, XLSX and PPTX comments, so the same code handles review comments from every format.

Attached to the text they cover

A highlight that reports only a page number tells you little. AILANG Parse compares the highlighted area (/QuadPoints) with the positions of the words on the page, so a highlight reports the text it covers:

{
  "type": "comment",
  "author": "Laura",
  "text": "This indemnity is far too broad.",
  "anchorText": "shall indemnify",
  "anchorKind": "range",
  "anchored": true
}

A word counts as highlighted when its centre is inside the highlight. A highlight drawn slightly wide touches the next word, and counting every touched word would include words the reviewer never marked. When word positions are not available, the annotation is still returned, with anchored set to false and no guessed text.

Compressed PDFs. Some PDFs store annotations in a compressed form (an /ObjStm object stream) that AILANG Parse cannot read. In that case it returns the annotations it found and sets a mayBeIncomplete flag, and the CLI tells you, so you know the list may be missing some.

Local Processing with Ollama

For sensitive documents that must not leave your network, use Ollama as the AI provider. Install Ollama, download a model that can read images, and name it with --ai. Nothing is sent to a cloud service.

# Install Ollama and pull a vision model
ollama pull llama3.2-vision

# Parse PDF fully locally
docparse confidential-report.pdf --pdf-backend ai --ai ollama/llama3.2-vision

The output format is the same as with a cloud provider. You can develop with Ollama and run production on Gemini or Claude with the same code.

Use Cases

Scanned Document Digitization

Read scanned PDFs with an AI model. It reads handwritten notes, stamps and faded print that traditional OCR struggles with. The output is structured JSON, not plain text.

Invoice Processing

Extract line items, totals, dates and vendor details from PDF invoices. The AI works out the table from the layout, which copes with the many invoice formats vendors use.

Academic Paper Ingestion

Parse research papers into sections: abstract, methodology, results, references. The AI handles multi-column layouts, figure captions and equations, which rule-based PDF parsers often get wrong.

Legacy Archive Migration

Convert a PDF archive to structured JSON for a database or a knowledge base. Process thousands of documents in batch mode, with the AI provider that costs least at your volume.

Compliance Document Review

Parse regulatory filings, audit reports and policy documents from PDF into structured blocks. Give them to an LLM to check compliance, extract clauses or compare documents.

Networks With No Internet Access

Process classified or restricted documents entirely on your own hardware with Ollama. No internet connection is needed once the model is downloaded. The output is the same, so it fits your existing pipeline.

Try It

CLI

# Parse with Gemini (set GOOGLE_API_KEY)
GOOGLE_API_KEY="your-key" docparse report.pdf --pdf-backend ai --ai gemini-3.5-flash-lite

# Parse with Ollama (fully local)
docparse report.pdf --pdf-backend ai --ai ollama/llama3.2-vision

API

curl -X POST https://docparse.ailang.sunholo.com/api/v1/parse \
  -H "Content-Type: application/json" \
  -d '{"filepath":"sample_pdf","outputFormat":"markdown","apiKey":"YOUR_API_KEY"}'

# A scanned PDF: upload it and choose the AI backend
curl -X POST https://docparse.ailang.sunholo.com/api/v1/parse \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "filepath=@scan.pdf" \
  -F "pdfBackend=ai" \
  -F "outputFormat=markdown"

Python SDK

from ailang_parse import DocParse

client = DocParse(api_key="YOUR_API_KEY")

# Text PDFs need no AI. For a scan, choose the AI backend.
result = client.parse_file("report.pdf")
scan = client.parse_file("scan.pdf", pdf_backend="ai")

# The same blocks as Office formats
for block in result.blocks:
    if block.type == "table":
        print(f"Table: {len(block.rows)} rows")
    if block.type == "heading":
        print(f"H{block.level}: {block.text}")

Parse in Browser    API Reference

Frequently Asked Questions

How do I parse a PDF to JSON?

From the CLI, choose a PDF reader with --pdf-backend: pdftotext (the default, plain text, no AI), poppler, docling, liteparse or ai. Over the AILANG Parse API, send the PDF. Either way you get the same structured JSON as for Office formats.

Which AI providers are supported for PDF parsing?

Gemini (gemini-3.5-flash-lite), Claude (claude-sonnet-4-5-20250514), OpenAI (gpt-4o), and Ollama, which runs on your own machine. Switch with one flag.

Can I parse PDFs locally without sending data to the cloud?

Yes, and that is the default for every PDF. pdftotext handles PDFs that contain real text. Scanned and image-only PDFs go to docling automatically, with no flag. If you choose the AI backend, Ollama keeps that local too: set --ai ollama/llama3.2-vision or any model that can read images. Either way, no data leaves your machine.

Why would PDF parsing ever use AI?

A PDF records where each character is drawn, not the document’s structure. Recovering headings, tables and reading order from a scan needs a layout model (docling, used automatically for scans). Handwriting and pages that mix text and images need an AI model, which is used only when you pass --pdf-backend ai. When you have the original file, parse the DOCX.

Is the output format the same as Office parsing?

Yes. You get the same blocks (headings, text, tables, images) as for DOCX, XLSX and PPTX, whichever backend or provider you use. Your code handles every format the same way.

How much does PDF parsing cost?

AILANG Parse charges per API request. AI provider costs are separate, paid on your own key. Gemini Flash costs least at high volume. Ollama is free and runs on your hardware.