# Document to Structured Data — PDF, Excel, Word, CSV, Scans (`spudnicks/document-to-structured-data`) Actor

Turns PDFs, scanned images, XLSX, CSV and DOCX files into clean structured JSON: text blocks with page numbers, tables as lists of lists, document metadata and a flat CSV-friendly row. One dataset item per document, at $3.00 per 1,000 documents.

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

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

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

## 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 Structured Data

Turns documents into clean, structured JSON. Send PDFs, scanned images, Excel workbooks, CSVs or Word files; get back one dataset item per document — text broken into blocks with page numbers, tables as real rows and cells, document metadata, and a flat record that exports straight to CSV.

Built for the ordinary case that wastes the most time: a folder of documents that someone has to open, read and retype.

### What you get per document

| Field | Meaning |
| --- | --- |
| `source`, `fileName`, `docType` | where it came from and what it is |
| `pageCount`, `sheetCount`, `unitCount` | pages or sheets, whichever applies |
| `blockCount`, `charCount` | size of the extracted text |
| `blocks[]` | text blocks with page number, type, text and position |
| `tables[]` | every table as rows and cells, not a picture of a table |
| `metadata{}` | producer, author, dates, page size, sheet names, OCR engine |
| `text` | the whole document as plain text with `[page n]` markers |
| `warnings[]` | anything that degraded, so nothing fails silently |
| `flat{}` | scalar-only view for spreadsheet and CSV export |

### Input

```json
{
  "documentUrls": ["https://example.com/report.pdf"],
  "maxPages": 50,
  "ocrImages": true,
  "includeFlatRow": true
}
```

Point it at public URLs. Mixed batches are fine — a PDF, a workbook and a scan in one run all come back in the same shape.

### Output

One dataset item per document, for example:

```json
{
  "fileName": "quarterly.pdf",
  "docType": "pdf",
  "pageCount": 12,
  "tableCount": 3,
  "tableCellCount": 148,
  "tables": [{ "page": 2, "rowCount": 4, "columnCount": 3, "rows": [["Region", "Q1", "Q2"], ["North", "1240", "1380"]] }],
  "warnings": []
}
```

### Pricing

Pay per event: **$3.00 per 1,000 documents** processed. Failed downloads and unsupported files are not charged.

### Honest limits

- Scanned pages go through OCR; handwriting, stamps and very low-resolution scans produce text that needs checking. Those cases are reported in `warnings[]`, not hidden.
- A layout that mixes columns and tables can split a table into two blocks; the warnings list says when it happened.
- Password-protected files are reported as an error rather than guessed at.

### Support

Open an issue on this actor's page. Include the `warnings[]` from your run — that is usually enough to see what the document did.

# Actor input Schema

## `documentUrls` (type: `array`):

Public http(s) URLs of the documents to process. Local file paths also work when the actor is run with the CLI.

## `maxPages` (type: `integer`):

Stop reading a document after this many pages/sheets. Cost is one event per document regardless.

## `ocrImages` (type: `boolean`):

Run OCR on PNG/JPEG/TIFF scans. Disable for faster runs when you only need image metadata.

## `includeFlatRow` (type: `boolean`):

Add a flat{} object of scalar fields (page counts, table TSV, text preview) so the dataset exports cleanly to CSV.

## Actor input object example

```json
{
  "documentUrls": [
    "https://example.com/report.pdf"
  ],
  "maxPages": 50,
  "ocrImages": true,
  "includeFlatRow": true
}
```

# Actor output Schema

## `documents` (type: `string`):

One record per document: text blocks with page numbers, tables, metadata, warnings and a flat CSV-friendly row.

# 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 = {
    "documentUrls": [
        "https://example.com/report.pdf"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("spudnicks/document-to-structured-data").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 = { "documentUrls": ["https://example.com/report.pdf"] }

# Run the Actor and wait for it to finish
run = client.actor("spudnicks/document-to-structured-data").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 '{
  "documentUrls": [
    "https://example.com/report.pdf"
  ]
}' |
apify call spudnicks/document-to-structured-data --silent --output-dataset

```

## MCP server setup

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

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/GjYHRapbcjNgCMw0A/builds/5y5o7AWyCrADXbOJY/openapi.json
