DEV Community

DevToolsmith
DevToolsmith

Posted on

PDF to JSON in One API Call: A Complete Guide to Document Extraction

Every business processes PDFs — invoices, contracts, receipts, compliance documents, bank statements. Extracting structured data from them is still painfully manual for most teams. This guide covers why, how, and when to use API-based PDF extraction.

Why PDF Extraction Is Hard

PDFs were designed for printing, not for data extraction. Under the hood, a PDF stores text as individually positioned characters on a canvas. There is no concept of "table", "header", or "invoice number" in the raw format.

This means:

  • Copy-paste loses structure — tables become jumbled text, columns merge
  • Manual data entry is slow — a skilled person processes maybe 20 invoices per hour
  • OCR tools often fail — scanned PDFs produce garbled output without expensive post-processing
  • Custom regex parsers break — every vendor uses a different invoice format

The result? Businesses spend thousands of hours per year on manual PDF data entry. Accounting teams, legal departments, logistics operations — they all suffer from the same problem.

How API-Based PDF Extraction Works

Modern PDF extraction APIs solve this by combining multiple techniques:

1. Text Layer Parsing

For digitally-created PDFs (not scanned), the API extracts the text layer directly. This preserves the original characters without OCR errors.

2. Layout Analysis

The API analyzes the spatial relationships between text elements. It identifies:

  • Tables — by detecting grid patterns and aligned columns
  • Key-value pairs — like "Invoice Number: INV-2025-042"
  • Headers and sections — by font size, weight, and position
  • Lists and line items — by indentation and bullet patterns

3. Structured JSON Output

Instead of raw text, you get clean, typed JSON:

{
  "invoice_number": "INV-2025-042",
  "date": "2025-03-15",
  "vendor": "Acme Corp",
  "total": 1250.00,
  "tax": 250.00,
  "currency": "EUR",
  "line_items": [
    {"description": "Web Development", "quantity": 1, "price": 1000.00},
    {"description": "Hosting (Annual)", "quantity": 1, "price": 250.00}
  ]
}
Enter fullscreen mode Exit fullscreen mode

Common Use Cases

Invoice Processing

Who needs it: Accounting firms, AP departments, fintech companies
What you extract: Invoice number, date, vendor, line items, totals, tax amounts, payment terms
Volume: Typically 100-10,000 invoices/month

Contract Analysis

Who needs it: Legal teams, M&A departments, compliance officers
What you extract: Parties, effective dates, key clauses, termination conditions, signatures
Volume: Typically 10-500 contracts/month

Receipt Processing

Who needs it: Expense management platforms, accounting software
What you extract: Merchant name, date, items purchased, payment method, total
Volume: Can reach 50,000+ receipts/month for large platforms

Bank Statement Parsing

Who needs it: Lending platforms, financial advisors, audit firms
What you extract: Account info, transaction list, dates, amounts, running balance
Volume: Typically 50-5,000 statements/month

Logistics Documents

Who needs it: Freight forwarders, customs brokers, warehouse management
What you extract: Consignment numbers, addresses, weights, HS codes, delivery dates
Volume: Highly variable, can reach 10,000+/month

How DocuMint Works

DocuMint converts any PDF to structured JSON with one API call:

  1. Upload your PDF file (or pass a URL)
  2. DocuMint parses the document structure automatically
  3. Get JSON back — clean, typed, ready for your database

No machine learning training required. No templates to configure. It works out of the box with any PDF format.

Quick Start

Visit parseflow.dev, upload a PDF, and see the extracted JSON immediately. The free tier includes 100 pages per month — enough to evaluate the quality on your actual documents.

For teams processing higher volumes, paid plans start at $19/month for 1,000 pages.

When to Use a PDF API vs Building Your Own

Use an API when:

  • You process more than 10 different PDF formats
  • Volume exceeds 50 PDFs per day
  • You need consistent, structured output across formats
  • Manual entry is creating bottlenecks in your workflow
  • You are building automated pipelines (ETL, data ingestion)

Build your own when:

  • You have exactly one PDF format that never changes
  • Volume is very low (less than 5 per week)
  • You need 100% accuracy on complex layouts (add human review on top)
  • You have specific regulatory requirements for data processing location

Integration Example

// Node.js example
const FormData = require('form-data');
const fs = require('fs');

const form = new FormData();
form.append('file', fs.createReadStream('invoice.pdf'));

const response = await fetch('https://parseflow.dev/api/extract', {
  method: 'POST',
  headers: { 'Authorization': 'Bearer YOUR_API_KEY' },
  body: form
});

const data = await response.json();
console.log(data.invoice_number); // "INV-2025-042"
console.log(data.total);          // 1250.00
Enter fullscreen mode Exit fullscreen mode

Related Tools

  • CaptureAPI — capture web pages as PDF/screenshot before extraction
  • AccessiScan — scan websites for WCAG accessibility compliance
  • CompliPilot — check AI products against EU AI Act requirements
  • ToolKit Online — 143+ free developer tools

FAQ

How accurate is automated PDF extraction?

For digitally-created PDFs (not scanned), accuracy is typically 95-99%. Scanned PDFs depend on scan quality — clean scans achieve 90-95%, poor quality scans may need OCR preprocessing.

Can it handle tables?

Yes. DocuMint detects table structures by analyzing spatial relationships between text elements. Multi-column tables, nested tables, and tables spanning multiple pages are all supported.

What about non-English documents?

DocuMint supports all Latin-alphabet languages natively. For CJK (Chinese, Japanese, Korean) and Arabic documents, accuracy depends on the PDF encoding.

Is my data secure?

Documents are processed in memory and never stored permanently. All API communication uses TLS 1.3 encryption. GDPR compliant.


Stop copy-pasting from PDFs. Try DocuMint — 100 free pages/month, structured JSON output, zero configuration.

What types of PDFs does your team process most? Share in the comments.

Top comments (0)