# PDF Extractor — Text, Metadata and Scored Tables (`xtracto/pdf-extractor`) Actor

Turn any PDF URL into clean text plus document metadata, and detect scanned PDFs that need OCR. Tables are extracted best-effort with a quality score, so low-quality grids are dropped rather than billed. Keyless, HTTP-only.

- **URL**: https://apify.com/xtracto/pdf-extractor.md
- **Developed by:** [Farhan Febrian Nauval](https://apify.com/xtracto) (community)
- **Categories:** AI, Developer tools
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.50 / 1,000 results

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.
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

## PDF Extractor — Text, Metadata and Scored Tables

Turn any PDF URL into clean text plus document metadata. Detects scanned PDFs that
need OCR, and flags PDFs whose font encoding destroyed the word boundaries. Tables
are extracted best-effort, with a quality score — and low-quality grids are dropped
rather than billed to you.

Keyless, HTTP-only, no browser.

### What you get

| Field | Meaning |
|---|---|
| `text`, `charCount`, `wordCount` | The document as text |
| `pageTexts` | One entry per page, when `includePageTexts` is on — lets you cite page numbers |
| `pageCount`, `pagesRead` | Total pages, and how many were read |
| `likelyScanned`, `charsPerPage` | Whether this is images rather than text |
| `spacingLooksBroken`, `spaceRatio` | Whether word boundaries survived extraction |
| `title`, `author`, `subject`, `creator`, `producer` | Document metadata |
| `createdAt`, `modifiedAt` | Normalised from the PDF date format |
| `tables`, `tableCount`, `tableStrategy` | Tables that passed the quality gates |
| `tablesDroppedAsLowQuality` | How many candidates were rejected, so nothing is silently discarded |

### Read this before turning tables on

**Table detection in PDFs is unreliable, and this actor is built to admit it.**
Tested against three real documents:

| Document | Result |
|---|---|
| BLS CPI release | One genuine table — 5 rows × 4 columns, 95% filled |
| arXiv paper | **No tables**, 7 candidates rejected — its tables have no ruling lines and every strategy produced prose in a grid |
| IRS 1040 form | **No tables**, 19 candidates rejected — pdfplumber reports the form's ruled boxes, 85% empty |

So one of three documents yielded a table. `extractTables` is **off by default**, and
when on, three strategies are tried and every candidate must clear four gates:

- **at least 3 rows and 2 columns** — anything smaller is page furniture
- **at least 35% of cells populated** — a genuine statistical table measured 95%; the IRS form's boxes measured 14.6%
- **under 25% mid-word splits** — the `text` strategy builds columns from whitespace positions, so a paragraph becomes a wide, well-filled, consistent grid that reads `['Transmissio', 'n of mat', 'erial in', …]`. Shape alone is not evidence of a table
- a combined score above `minTableQualityPercent`

`tablesDroppedAsLowQuality` tells you how many were thrown out, so a zero-table
result is distinguishable from a PDF that was never examined.

### Things worth knowing

**A 404 is often served as `text/html`.** Existence is judged on the `%PDF-` magic
bytes, not on the status code or content type, and a non-PDF body is reported as
`not_a_pdf` with what it actually started with.

**Scanned PDFs are detected, not silently empty.** Under roughly 40 characters per
page means the document is images. The row says so and the log warns, rather than
returning blank text.

**Some PDFs lose their spaces.** Certain font encodings extract as
`Providedproperattributionisprovided` — real text, no word boundaries. The arXiv
paper tested at a 0.028 space ratio against 0.158 and 0.203 for two government
documents, so the cases separate cleanly. This is **reported, not repaired**:
re-inserting spaces needs a dictionary and would be guessing at the document's
actual words.

### Failure reporting

| `_error` | Meaning |
|---|---|
| `not_a_pdf` | The body is not a PDF — often an HTML error page |
| `pdf_unreadable` | A PDF that could not be parsed, with the underlying reason |
| `too_large` | Above the size limit |
| `request_failed` | Never reached, with the cause |

### Related

**Sitemap Crawler** finds a site's PDF URLs; **Website Content Extractor** does the
same job for HTML pages.

# Actor input Schema

## `urls` (type: `array`):

One PDF URL per line.

## `includeText` (type: `boolean`):

The whole document as one text field. Turn off if you only want metadata and tables.

## `includePageTexts` (type: `boolean`):

Adds an array with one entry per page, so you can cite page numbers.

## `extractTables` (type: `boolean`):

Off by default, and deliberately so: table detection in PDFs is unreliable. Across three real documents, only one produced a usable grid — the others gave single-column blobs or grids over 70% empty. When on, three strategies are tried and every table is scored.

## `minTableQualityPercent` (type: `integer`):

A table scores on having real columns, being mostly populated, and having consistent row widths. Below this threshold it is dropped and counted rather than returned as data. 0 returns everything found, including the single-column blobs pdfplumber sometimes reports as tables.

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

0 reads the whole document. Useful for very long reports where the first pages carry the summary.

## `concurrency` (type: `integer`):

How many PDFs to fetch and parse at once. PDFs are large, so keep this modest.

## `proxyConfiguration` (type: `object`):

Optional. Most document hosts serve PDFs to anything.

## Actor input object example

```json
{
  "urls": [
    "https://www.bls.gov/news.release/pdf/cpi.pdf"
  ],
  "includeText": true,
  "includePageTexts": false,
  "extractTables": false,
  "minTableQualityPercent": 45,
  "maxPages": 0,
  "concurrency": 3
}
```

# Actor output Schema

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

One row per scraped record, stored in the run's default dataset.

# 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 = {
    "urls": [
        "https://www.bls.gov/news.release/pdf/cpi.pdf"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("xtracto/pdf-extractor").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 = { "urls": ["https://www.bls.gov/news.release/pdf/cpi.pdf"] }

# Run the Actor and wait for it to finish
run = client.actor("xtracto/pdf-extractor").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 '{
  "urls": [
    "https://www.bls.gov/news.release/pdf/cpi.pdf"
  ]
}' |
apify call xtracto/pdf-extractor --silent --output-dataset

```

## MCP server setup

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

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/VI9QfN0UcGNZfzC3o/builds/ExJ9KgGb0hKhZKsTG/openapi.json
