# Document to JSON — PDF, Invoice & Table Extractor (`istmobot/document-to-json`) Actor

Turn PDFs, scans and photos (invoices, receipts, bank statements, forms, tables) into text or structured JSON. Input: document URLs, plus optional field names or a JSON schema. Output: one row per document with page text, or with fields and tables as JSON.

- **URL**: https://apify.com/istmobot/document-to-json.md
- **Developed by:** [Istmobot](https://apify.com/istmobot) (community)
- **Categories:** AI, Developer tools, Automation
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.60 / 1,000 page of texts

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Document to JSON — PDF, Invoice & Table Extractor

Turn **PDFs, scans and photos** into data you can use. Give the Actor links to invoices, receipts, bank statements, purchase orders, forms, menus or reports, and get back either the **text of every page** or **structured JSON with fields and tables**. No templates, no training, no OCR setup.

### What is Document to JSON?

It reads documents from public URLs and returns one dataset row per document. It has two modes:

- **Text mode**: the text of each PDF page. Fast and very cheap. For PDFs that have a text layer.
- **Structured mode**: fields and tables as JSON, read with AI. It also reads scans, photos and handwriting, in any language.

Typical uses:

- **Accounts payable**: invoice number, dates, vendor, totals, tax and line items from supplier invoices.
- **Expense reports**: merchant, date, total and currency from photos of receipts.
- **Bank and card statements**: every transaction as a table row.
- **Forms and contracts**: the fields you name, as clean keys.
- **Feeding an LLM or a search index**: page text of large PDF sets.

### What data can I get?

| Field | Meaning |
|---|---|
| `url` | The document you sent |
| `fileType` | `pdf`, `png`, `jpeg`, `webp` or `gif`, detected from the file itself |
| `pages` | Pages in the document (images count as 1) |
| `pagesProcessed` | Pages read and charged |
| `truncated` | `true` when the document has more pages than were read |
| `text`, `pageTexts` | Text mode: the whole text, and one text per page |
| `data` | Structured mode: the extracted JSON (see below) |
| `error`, `errorCode` | Present only on failed documents, which are free |

In structured mode with no fields chosen, `data` holds:

| Key | Meaning |
|---|---|
| `documentType` | For example `invoice`, `receipt`, `bank statement` |
| `language` | ISO 639-1 code of the main language |
| `summary` | One or two sentences about the document |
| `fields` | Every labelled value as `snake_case: value`, copied as written |
| `tables` | Every table: `title`, `columns` and `rows` (one object per row, keyed by column) |

When you set **Fields to extract** or a **JSON schema**, `data` has exactly your keys.

### How much does it cost?

Pay-per-event pricing. You pay only for pages that were read successfully.

| Event | Price |
|---|---|
| Actor start | $0.005 per run |
| `page-text` (text mode, per page) | $0.002 |
| `page-structured` (structured mode, per page) | $0.01 |

Examples: 1,000 one-page invoices as structured JSON cost about **$10**. The text of a 200-page PDF set costs about **$0.40**.

Failed documents (bad link, unsupported file, unreadable PDF) are **never charged**. Set a **maximum cost per run** and the Actor stops cleanly when it is reached. On the Apify free plan, structured mode reads the first 3 pages of each run so you can try it.

### How to use Document to JSON

1. Click **Try for free**.
2. Paste one or more document URLs.
3. Choose **text** or **structured**.
4. Optional, structured mode: name the fields you want, or paste a JSON schema.
5. Click **Start** and download the dataset as JSON, CSV or Excel, or read it through the API.

### ⬇️ Input

```json
{
    "documents": ["https://example.com/invoices/INV-2026-0418.pdf"],
    "mode": "structured",
    "fields": [
        "invoice_number: the invoice number",
        "issue_date: issue date as YYYY-MM-DD",
        "vendor_name: who issued the invoice",
        "total: total amount due, number only",
        "currency: ISO currency code"
    ],
    "maxPagesPerDocument": 5
}
```

| Field | Default | Description |
|---|---|---|
| `documents` | required | Public URLs of PDF, PNG, JPG, WEBP or GIF files. PDFs up to 20 MB, images up to 3.7 MB |
| `mode` | `text` | `text` or `structured` |
| `maxPagesPerDocument` | `10` | Pages read per document. Structured mode reads at most 20 |
| `fields` | empty | Structured mode. Lines of `name: description`. Each comes back as text or `null` |
| `jsonSchema` | empty | Structured mode. A JSON schema for nested output such as line items. Overrides `fields` |
| `instructions` | empty | Structured mode. Formatting hints, e.g. "Dates as YYYY-MM-DD" |

### ⬆️ Output

Structured mode, no fields chosen:

```json
{
    "url": "https://example.com/invoices/INV-2026-0418.pdf",
    "fileType": "pdf",
    "pages": 2,
    "pagesProcessed": 2,
    "truncated": false,
    "data": {
        "documentType": "invoice",
        "language": "en",
        "summary": "Invoice from Northwind Data Services Ltd. to Acme Retail GmbH with a total due of 979.70 EUR including 23% VAT.",
        "fields": {
            "invoice_number": "INV-2026-0418",
            "issue_date": "2026-11-03",
            "due_date": "2026-12-03",
            "seller_name": "Northwind Data Services Ltd.",
            "subtotal": "796.50 EUR",
            "vat_amount": "183.20 EUR",
            "total_due": "979.70 EUR",
            "iban": "IE29 AIBK 9311 5212 3456 78"
        },
        "tables": [
            {
                "title": "Invoice line items",
                "columns": ["Description", "Qty", "Unit price", "Amount"],
                "rows": [
                    { "Description": "Web scraping setup", "Qty": "1", "Unit price": "450.00", "Amount": "450.00" },
                    { "Description": "Monthly data feed (November)", "Qty": "2", "Unit price": "120.00", "Amount": "240.00" }
                ]
            }
        ]
    }
}
```

### Error items

A document that cannot be processed comes out as a free row:

```json
{ "url": "https://example.com/page.html", "errorCode": "UNSUPPORTED_FILE", "error": "Not a PDF, PNG, JPG, WEBP or GIF file (the link may point to a web page)." }
```

| `errorCode` | Meaning |
|---|---|
| `INVALID_URL`, `DOWNLOAD_FAILED` | The link is wrong, private or the server refused it |
| `UNSUPPORTED_FILE` | The file is not a PDF or a supported image |
| `FILE_TOO_LARGE` | Over 20 MB (PDF) or 3.7 MB (image) |
| `UNREADABLE_PDF` | Damaged or password-protected |
| `NO_TEXT_LAYER`, `NEEDS_STRUCTURED_MODE` | Text mode got a scan or an image: use structured mode |
| `EXTRACTION_FAILED` | The document could not be read; try fewer pages per document |

### Integrations & API

```bash
curl -X POST "https://api.apify.com/v2/acts/istmobot~document-to-json/run-sync-get-dataset-items?token=YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"documents":["https://example.com/invoice.pdf"],"mode":"structured"}'
```

```python
from apify_client import ApifyClient

client = ApifyClient("YOUR_TOKEN")
run = client.actor("istmobot/document-to-json").call(run_input={
    "documents": ["https://example.com/invoice.pdf"],
    "mode": "structured",
})
for doc in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(doc["data"]["fields"])
```

Works with Make, Zapier and n8n through the Apify apps, and with webhooks: start a run whenever a new file lands in your storage, and send the JSON to your accounting tool or spreadsheet.

### 🤖 Use with AI agents (MCP)

Add the Actor to any MCP client with `https://mcp.apify.com?tools=istmobot/document-to-json`. Example prompt: "Read this invoice PDF and give me the vendor, total and line items."

### ❓ FAQ

**Does it read scans and photos?** Yes, in structured mode. Text mode needs a PDF with a text layer and tells you when a file has none.

**Which languages work?** Structured mode reads documents in most languages and keeps values as written. Field names in the default output are in English.

**Are values changed or guessed?** No. Values are copied as written in the document. A field the document does not contain comes back as `null`. Always review amounts before you post them to a ledger.

**How do I get line items as typed numbers?** Use `jsonSchema` with an `items` array and `number` types, and add an instruction such as "Amounts as numbers with a dot as decimal separator".

**How many pages can one document have?** Any number in text mode. Structured mode reads the first 20 pages of each document; split longer files.

**Is my document stored?** The file is downloaded for the run, read, and not kept by the Actor. Results stay in your own Apify dataset under your retention settings. Structured mode sends the pages to Anthropic's Claude API for reading.

**Can it read private files?** The URL must be reachable without login. Use a signed or temporary link from your storage.

### Your feedback

Found a document it reads badly, or need another format? Open an issue on the Actor's **Issues** tab and attach an example if you can.

# Actor input Schema

## `documents` (type: `array`):

Public links to PDF, PNG, JPG, WEBP or GIF files, e.g. https://example.com/invoice-0418.pdf. One output row per document. PDFs up to 20 MB, images up to 3.7 MB.

## `mode` (type: `string`):

"text": the text of each PDF page, fast and cheap, for PDFs that have a text layer. "structured": fields and tables as JSON, read with AI; works on scans, photos and handwriting too.

## `maxPagesPerDocument` (type: `integer`):

Only the first pages of each document are read, e.g. 10. You pay per page read. Structured mode reads at most 20 pages per document.

## `fields` (type: `array`):

Structured mode only. One field per line as "name: what it is", e.g. "invoice_number: the invoice number" or "total: total amount as a number with no currency". Each field comes back as text, or null when the document does not have it. Leave empty to get every labelled value and every table.

## `jsonSchema` (type: `object`):

Structured mode only. A JSON schema of the object you want back, for nested data such as line items, e.g. {"type":"object","properties":{"total":{"type":"number"},"items":{"type":"array","items":{"type":"object","properties":{"description":{"type":"string"},"amount":{"type":"number"}}}}}}. Keys you do not mark as required come back as null when missing. Overrides "Fields to extract".

## `instructions` (type: `string`):

Structured mode only. Optional hints on what to extract or how to format it, e.g. "Dates as YYYY-MM-DD. Amounts as numbers with a dot as decimal separator."

## Actor input object example

```json
{
  "documents": [
    "https://api.apify.com/v2/key-value-stores/amcfiaWTUZQpeWXjE/records/sample-invoice.pdf"
  ],
  "mode": "structured",
  "maxPagesPerDocument": 10
}
```

# Actor output Schema

## `results` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "documents": [
        "https://api.apify.com/v2/key-value-stores/amcfiaWTUZQpeWXjE/records/sample-invoice.pdf"
    ],
    "mode": "structured",
    "maxPagesPerDocument": 10
};

// Run the Actor and wait for it to finish
const run = await client.actor("istmobot/document-to-json").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "documents": ["https://api.apify.com/v2/key-value-stores/amcfiaWTUZQpeWXjE/records/sample-invoice.pdf"],
    "mode": "structured",
    "maxPagesPerDocument": 10,
}

# Run the Actor and wait for it to finish
run = client.actor("istmobot/document-to-json").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "documents": [
    "https://api.apify.com/v2/key-value-stores/amcfiaWTUZQpeWXjE/records/sample-invoice.pdf"
  ],
  "mode": "structured",
  "maxPagesPerDocument": 10
}' |
apify call istmobot/document-to-json --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,istmobot/document-to-json"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/IXkK4xrp57R23UQpg/builds/D2NpmAnCPAbizYf08/openapi.json
