Why convert a PDF to JSON?
PDFs are great for displaying documents. They’re not particularly convenient when you need to work with the contents in code.
A PDF might contain an invoice, a report, a form or a table, but getting that information into an application usually means extracting the text first and figuring out how it fits together.
JSON gives you something your code can actually work with.
Instead of dealing with a page full of positioned text, you can have:
{
"page": 1,
"text": "Invoice #1042",
"size": 18
}
You can loop over it, store it in a database, send it to another API, feed it into an LLM, or use the coordinates to draw something back on top of the original PDF.
How to convert a PDF to JSON
- Drop your PDF into the converter above.
- The PDF is parsed directly in your browser.
- Choose the JSON format you need.
- Copy or download the result.
For text-based PDFs, nothing is uploaded to a server.
You can also switch the output to Markdown, CSV, or plain text if JSON isn’t what you need.
When the data has to be right
Pulling text out of a PDF is the easy part. The harder part is knowing when the extraction is wrong, because wrong output usually looks completely fine.
On a single document you catch a dropped row or a misread figure by eye. Across thousands of them you don’t, and one wrong number can sit undetected until it breaks something downstream.
For the cases where that matters, the API does more than extract. The bank-statement endpoint reconciles its own output: it checks that opening balance plus credits minus debits equals the closing balance, and flags any statement that doesn’t add up. Plain extraction gives you JSON; the reconciliation check is what lets you trust it without reading every row yourself.
What does the JSON look like?
The default Structured format represents the document as pages containing text blocks.
For example:
{
"pages": [
{
"page": 1,
"text": "Invoice #1042\nBilled to: Acme Co\nTotal: $1,240.00",
"blocks": [
{ "text": "Invoice #1042", "size": 18 },
{ "text": "Billed to: Acme Co", "size": 11 },
{ "text": "Total: $1,240.00", "size": 11 }
]
}
]
}
Each text block includes its font size, which can be useful when you’re trying to distinguish headings from ordinary body text.
The output isn’t tied to a particular application or framework. It’s just JSON, so you can process it however you like.
Three ways to extract PDF data as JSON
Different applications need different levels of detail, so the converter has three output formats.
Structured
Pages contain their text and individual text blocks, including font sizes.
This is a good general-purpose format if you want to inspect or process the document while retaining some information about its visual structure.
By paragraph
Text is grouped into reading-order paragraphs.
This is useful when you’re preparing a document for an LLM, search index or RAG pipeline. You get larger, meaningful pieces of text without having to reconstruct paragraphs yourself.
Words + positions
Every word includes its position and dimensions on the page.
For example:
{
"text": "Invoice",
"x": 72,
"y": 84,
"width": 48
}
This is the format to use when where something appears matters.
It’s useful for highlighting search results, building PDF viewers, creating overlays, redaction, layout analysis and other applications that need to work with the original page.
You can also include the PDF’s metadata in the output, including fields such as the title, author, subject and creation date when they’re available.
PDF to JSON for LLMs and RAG
PDF extraction is increasingly used as the first step in document-processing pipelines.
If you’re sending a document into an LLM or RAG system, By paragraph is usually the most convenient starting point. It gives you text in reading order without the extra information from every individual word.
From there, you can split the paragraphs into chunks, generate embeddings and store the resulting data in your vector database.
For documents where structure matters more — such as invoices, forms or reports — the PDF to Markdown converter can be useful too. Markdown keeps headings and lists intact, which gives you more information to work with when creating chunks.
If you’re trying to extract specific fields or actual table data, that’s a different problem. The API can handle those cases with schema-based extraction, OCR and table detection.
PDF to JSON in code
The browser converter is useful for individual files. If you’re building an application or processing PDFs automatically, use the API.
curl -X POST https://api.pdftojson.dev/v1/extract \
-H "Authorization: Bearer $KEY" \
-F file=@document.pdf -F format=json
import requests
response = requests.post(
"https://api.pdftojson.dev/v1/extract",
headers={"Authorization": f"Bearer {KEY}"},
files={"file": open("document.pdf", "rb")},
data={"format": "json"},
)
data = response.json()
const form = new FormData();
form.append("file", fs.createReadStream("document.pdf"));
form.append("format", "json");
const data = await fetch("https://api.pdftojson.dev/v1/extract", {
method: "POST",
headers: { Authorization: `Bearer ${KEY}` },
body: form,
}).then((r) => r.json());
The API adds OCR for scanned PDFs, table extraction and automated processing.
Digital vs scanned PDFs
This distinction explains a lot of failed PDF extraction attempts.
A digital PDF contains an actual text layer. If you can select and copy a sentence from it in your PDF viewer, it’s probably a digital PDF. The browser converter can read that text directly.
A scanned PDF is usually just a collection of page images. You might be able to see the words perfectly clearly, but there aren’t actually any characters for a normal PDF extractor to read.
Those documents need OCR.
The browser converter handles PDFs with a text layer. The API can process scanned documents using OCR and a vision model.
Where PDF extraction gets difficult
Most ordinary documents are straightforward. Some PDFs are considerably less cooperative.
Scanned pages
There’s no text layer to extract, so OCR is required. The API handles this case.
Tables
A table may look like a grid to you while the PDF simply contains dozens of pieces of text positioned on a page. Recovering the actual rows and columns requires table detection.
For that use case, see PDF to CSV or use table extraction through the API.
Multiple columns
Two-column documents can be stored in an order that doesn’t match the way you’d naturally read them. The extractor uses the positions of text blocks to determine reading order, but unusual layouts can still require some cleanup.
Character spacing
Some PDFs position individual characters rather than complete words. A naive extractor can turn:
S t e p p i n g
into something that looks nothing like the original document.
The parser uses the gaps between characters to reconstruct words rather than blindly inserting spaces.
PDF to JSON vs other tools
pypdf, PyMuPDF and pdfplumber
These are capable Python libraries and good choices if you’re already building a PDF-processing application. You get more control, but you’re responsible for integrating and maintaining the extraction yourself.
Unstructured
Unstructured is designed for broader document-processing workflows, including use cases involving search and RAG. It’s useful when you need that wider pipeline rather than simply converting a PDF to JSON.
A chatbot
Uploading a PDF to a chatbot can be handy when you want to ask questions about one document. It’s not a particularly convenient way to build a repeatable extraction pipeline or process a large number of files.
The browser converter is for the simple case: upload a text-based PDF and get structured JSON without installing anything.
When you need OCR, table extraction or automated processing, the API provides the programmatic version.
Is PDF to JSON private?
For text-based PDFs, the browser converter processes the file locally. The PDF doesn’t need to be uploaded to the server.
OCR and table extraction through the API require the file to be sent for processing. API files are handled according to the service’s current data-retention policy.