# PDF to Text & OCR - Scanned PDFs, Images, Word, Japanese (`quietworkslab/pdf-text-extractor`) Actor

PDF to text and OCR: extract text from PDFs, scanned PDFs, images (PNG, JPEG, WebP) and Word by link, upload or key-value store. Scans and photos go through AI OCR. Lines joined, headers and page numbers removed, Japanese-ready. $0.003 per 20 text pages, $0.004 per OCR page + AI cost.

- **URL**: https://apify.com/quietworkslab/pdf-text-extractor.md
- **Developed by:** [Quiet Works Lab](https://apify.com/quietworkslab) (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 $2.10 / 1,000 documents

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/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 to Text & OCR - Scanned PDFs, Images, Word, Japanese

Get clean text out of **PDF and Word (DOCX) files**, and with **OCR** out of **scanned PDFs and images** (PNG, JPEG, WebP), from **direct file links**, a key-value store in your Apify account or files you upload: wrapped lines are joined back into paragraphs (**no extra spaces between Japanese characters**), **headers, footers and page numbers are removed**, and you get one dataset row per document or per page.

**Price: $0.003 per 20 PDF pages** with a text layer (or per 50,000 characters of a Word file), and **$0.004 per OCR page** (a scanned page or an image read by the AI), on the FREE tier, less with Apify Store discounts (see [Pricing](#pricing)). **The AI model used for OCR is billed separately** to your Apify account by Apify's `apify/openrouter` Actor at OpenRouter's price, without any markup (about $0.0005-0.002 per page on paid Apify plans, about 10 times that on the Free plan). The built-in samples, files that fail, blank pages, pages the OCR could not read and pages left by your limits have no charge of this Actor; Apify's Actor start event ($0.00005 with the default 1 GB of memory) applies to every run. With `ocr: "off"` nothing is sent to any AI.

What the built-in sample PDF gives (3 pages, Japanese and English). Before, as the lines sit in the PDF, page 1:

```text
Quiet Works Lab — 見本の文書 / Sample document

- 1 -
PDF Text Extractor の見本 / Sample document

この文書は、PDF Text Extractor の動きを確かめるための見本です。日本語の文章は、PDF の中で
は行ごとに切れて入っています。この Actor は、折り返しの改行を段落にまとめ直し、漢字やかな
の間に余計な空白を入れません。そのまま検索や要約、RAG の材料に使えます。
```

After (the default settings; the running header stays where it first appears and is removed from pages 2 and 3):

```text
Quiet Works Lab — 見本の文書 / Sample document

PDF Text Extractor の見本 / Sample document

この文書は、PDF Text Extractor の動きを確かめるための見本です。日本語の文章は、PDF の中では行ごとに切れて入っています。この Actor は、折り返しの改行を段落にまとめ直し、漢字やかなの間に余計な空白を入れません。そのまま検索や要約、RAG の材料に使えます。
```

The row of the built-in scanned sample (a page picture without any text layer; in the default run its OCR text is prepared, so there is no AI call; text shortened and a few fields left out here):

```json
{"status": "ok", "source": "sample", "fileName": "sample-scan.pdf", "format": "pdf", "pageFrom": 1, "pageTo": 1, "pageCount": 1,
 "text": "Quiet Works Lab - Scanned Sample\n\nThis page is a picture of printed text, made for PDF Text Extractor. …\n\nこのページは、PDF Text Extractor の見本として作った文字の画像です。…",
 "charCount": 324, "emptyPages": 1, "needsOcr": true, "textSource": "ocr", "ocrPages": 1, "ocrPrepared": true,
 "ocrNote": "Built-in sample: the OCR text is prepared (no AI call, not charged).", "chargedEvents": 0, "chargedOcrPages": 0, "errorCode": null}
```

Click **Try for free** (free Apify account), then **Start**. Without links, a store or uploads, the Actor reads its three built-in samples (the PDF above, a small Word file with a heading, two paragraphs and a table, and the scanned page, all written for this Actor) and writes three rows within seconds. The scanned page is drawn for OCR like any scan, but its text comes from the sample's known text: no AI call, no charge.

### Typical uses

- Turn PDF reports, manuals, contracts and papers into plain text for search, summaries or an LLM.
- Read scanned PDFs, photos of documents and screenshots, also dark-mode ones (a phone screenshot is one OCR page; a long screenshot is cut into parts of up to 2,800 px).
- Prepare documents for RAG: one row per page (`splitBy: page`), or Markdown with headings.
- Extract Japanese PDFs without the stray spaces and broken lines that make them hard to search or chunk.
- Read the PDFs, Word files or images that another Actor saved in its key-value store, right after it finishes.

Only use files you have the right to use.

### How it works

1. **Files in**: give **direct links** to PDF, DOCX, PNG, JPEG or WebP files (one GET per link, see [File links](#file-links)), choose a **key-value store** (optionally only the keys that start with a prefix), and/or **upload files** in the input form. They are read one at a time: the store, the uploads, then the links. Store records that are not PDF, DOCX or (with OCR on) images are skipped. The format is detected from the file's first bytes, not from its name.
2. **Checks before any charge**: the file size (100 MB; images 25 MB and 60 megapixels, read from the header before the image is decoded), the memory the file needs, the page count (2,000 per file, or the pages you choose) and whether your maximum cost per run still covers the work. A file that fails a check gets a row with the reason and is not charged.
3. **Reading the text layer**: PDFs are read with pdf.js (fonts are never run as code, no scripts) in a separate worker that is stopped after 120 seconds per file, or as soon as the run uses more than 60% of its memory (some small PDFs unpack to gigabytes): that file fails with `TOO_LARGE_FOR_MEMORY` and the run goes on with the next one. The Japanese character maps that come with pdf.js are used. DOCX files are unpacked with size and count limits; document type declarations are refused, so no external entities are ever read.
4. **OCR** (`ocr: auto`, the default): the pages without a usable text layer go to OCR: all pages of a scan (a PDF with fewer than 10 characters of text, or whose characters are all unreadable), or the empty pages of a PDF where half or more of the pages have no text (the other pages keep their text layer), and every image. With `ocr: always`, every PDF page goes to OCR. Each page is drawn at about 2,000 px on its long side (A4 at about 170 dpi) in another worker under the same memory watchdog, with pdf.js's own decoders for JPEG, JPEG 2000, JBIG2 and CCITT fax scans. An image is drawn at its own size (scaled down only when it is wider than 2,000 px). **An image up to about 2,000 x 2,800 px is one OCR page** (a phone screenshot of 1,080 x 2,400 or 1,170 x 2,532, a US Legal page too); a taller one (a long screenshot, a receipt) is cut into parts of at most 2,800 px at the lightest band of rows (the gap between two lines when there is one; a photo or a pattern without a gap may be cut across a line), and each part is one OCR page. The width is never made smaller to have fewer parts: past 40 parts in one image or page, the rest is not read and not charged (the row says so). A page or part with almost no ink, darker or lighter than its background (so light text on a dark background counts), is **blank**: it is not sent and not charged. The others are sent as JPEG to the AI model **Google Gemini 3.1 Flash-Lite** (`google/gemini-3.1-flash-lite`; if OpenRouter has no endpoint for it, `google/gemini-3.5-flash-lite`) through Apify's official `apify/openrouter` Actor, up to 4 at a time, with fixed instructions: transcribe all text exactly in reading order, every character and punctuation mark as printed and no word changed, no spaces between Japanese characters, vertical Japanese top to bottom and right to left, one line per paragraph (`lineJoin: smart`, the wrapped lines joined) or the page's line breaks (`keep`), tables as Markdown tables (Markdown) or as lines with tab-separated cells (plain text). The answer must start with a fixed marker line: anything before it is dropped, an answer without it (a comment instead of the text) is asked for once more and then fails that page (not charged), and a fixed word after it means "no text" (not charged). With `lineJoin: smart`, lines the AI left broken inside a paragraph are joined as in the text layer (never table rows, list items or headings). An answer cut by the AI's output limit (2,048 tokens) is redone in two halves (and a half again in two); a half that fails keeps the text of the other. The results are put back in page order with the text-layer pages.
5. **Cleaning** (text layer): the pieces of each line are put together without spaces between kanji and kana; vertical text (tategaki) is read column by column, right to left; page numbers are removed (a bare number only when it goes up with the page); a line at the top or bottom that is exactly the same on at least half of the pages stays on the first page where it appears and is removed from the others; a line that differs only in a number going up with the page is removed (see the [FAQ](#faq)); wrapped lines are joined into paragraphs, and an English word broken by a hyphen at a line end is mended. Then all text, OCR text too, is tidied (`normalize`).
6. **Rows and charge**: the rows of a document are saved, then the progress, then the document is charged. A file is never charged twice, also when Apify moves the run to another server; OCR pages already read are not sent to the AI again after such a move.

### Input

| Field | What it does | Default |
|---|---|---|
| `fileUrls` | Direct links to PDF, DOCX, PNG, JPEG or WebP files (not web pages), up to 100 per run | empty |
| `keyValueStoreId` | A key-value store in your account with PDF, DOCX or image files (store picker) | empty |
| `keyPrefix` | Only the store's keys that start with this text | empty (all) |
| `uploadedFiles` | Files uploaded in the input form (PDF and DOCX up to 100 MB, images up to 25 MB) | empty |
| `pages` | PDF pages to read, e.g. `1-5,10` or `20-` | all pages |
| `splitBy` | `document`: one row per file; `page`: one row per PDF page | `document` |
| `lineJoin` | `smart`: join wrapped lines into paragraphs (OCR text too); `keep`: keep the line breaks of the page | `smart` |
| `removeHeadersFooters` | Remove repeated headers and footers and page-number lines | `true` |
| `normalize` | `basic`, `japanese` (also full-width letters, half-width katakana, dashes) or `none` | `basic` |
| `outputFormat` | `text` or `markdown` (headings, lists, tables) | `text` |
| `maxFiles` | Stop after this many files | no limit |
| `ocr` | `auto`: OCR the pages without a usable text layer, and images; `always`: OCR every PDF page; `off`: text layer only, nothing is sent to an AI | `auto` |
| `maxOcrPages` | The most OCR pages sent to the AI in one run (1-5,000) | 200 on a paid plan, 20 on the Free plan |

With no links, store or uploads, the built-in samples are read (no charge of this Actor, no AI call). Example input for the API:

```json
{
    "fileUrls": ["https://example.com/reports/annual-report-2026.pdf", "https://example.com/scans/receipt.jpg"],
    "pages": "1-50",
    "splitBy": "page",
    "normalize": "japanese",
    "maxOcrPages": 50
}
```

#### File links

- Use the link to the file itself (it usually ends in `.pdf`, `.docx`, `.png` or `.jpg`), not a page that shows or links to it. A link that returns a web page fails with `NOT_A_DOCUMENT`. Files sent as `application/octet-stream` are fine: the first bytes decide.
- Each link is fetched once, with up to 5 redirects; private and local network addresses are refused, also after a redirect. The Actor does not log in or send cookies: a link that needs a login fails with `AUTH_REQUIRED`. Put such files in a key-value store or upload them.
- Limits per link: 100 MB, 60 seconds for the whole download, at least 250 KB/s on average. A server error is retried twice; 429 (too many requests) is not retried.
- Rows and logs show links without their query string (it can hold a token); `linkNumber` says which line of your list a row belongs to.
- After 20 links in a row have failed, the rest of the list is not tried (no rows, no charges).

#### Uploaded files

A file uploaded in the input form is stored in a new key-value store of your account. If your account keeps its storages private (the default), this Actor, which runs with limited permissions, may not open it: the row then names that store. Choose it in **Key-value store** and start again; its files are read once.

### Output

One row per document or image (or per PDF page with `splitBy: page`). Every row has the same fields:

| Field | Meaning |
|---|---|
| `status` | `ok` (text from the text layer, OCR or both), `no-text` (no text found: a scan with OCR off, an OCR that found no text, a blank page or image, pages left by a limit; not charged) or `failed` (see `errorCode`, not charged). With one row per page, a page that OCR could not read, or a blank one, says so in its own row (`failed` or `no-text`, with `errorCode`) while the document is counted once |
| `source`, `fileName`, `sourceUrl`, `linkNumber` | Where the file came from; links are shown without their query string |
| `format` | `pdf`, `docx`, `png`, `jpeg` or `webp` |
| `part` | 1, or 2, 3 ... when the text of one row would pass 7 MB |
| `pageFrom`, `pageTo`, `pageCount` | The PDF pages in this row (1 for an image) and in the whole file (`null` for DOCX and images) |
| `text`, `charCount` | The text and its number of characters |
| `textSource` | `text-layer`, `ocr`, `text-layer+ocr` (in page order) or `docx` |
| `ocrPages`, `ocrBlankPages`, `ocrFailedPages`, `ocrPagesLeft`, `ocrNote` | OCR pages read with text (each one `page-ocr`), blank pages not sent, pages OCR could not read, pages that needed OCR but were not sent (a limit or a stop), and a sentence on what happened |
| `emptyPages`, `needsOcr`, `garbledSuspected`, `verticalTextPages` | Pages without a text layer; whether the file needs OCR (half or more of the pages without text, text that looks garbled, or almost no text); whether the text layer of a PDF looks garbled (kept and not charged, see the [FAQ](#faq)); text-layer pages of vertical text |
| `title`, `author`, `producer`, `createdAt` | The document information, if the file has it |
| `removedLines` | Header, footer and page-number lines removed |
| `chargedEvents`, `chargedOcrPages` | `document-extracted` events (on the document's first row) and `page-ocr` events charged for this row |
| `ocrPrepared` | `true` only for the built-in scanned sample (prepared OCR text, no AI call) |
| `errorCode`, `errorMessage` | Why a file is `no-text` or `failed`, and what to do |

A 4-page scan with one blank page, read with OCR (`ocr: auto`, values as the local tests give them with a mocked AI):

```json
{"status": "ok", "fileName": "scan.pdf", "format": "pdf", "pageFrom": 1, "pageTo": 4, "pageCount": 4, "textSource": "ocr",
 "ocrPages": 3, "ocrBlankPages": 1, "ocrFailedPages": 0, "ocrPagesLeft": 0,
 "ocrNote": "1 blank page(s) were not sent to the AI (not charged).", "chargedEvents": 0, "chargedOcrPages": 3, "errorCode": null}
```

Error codes: `NO_TEXT_LAYER` (a PDF with fewer than 10 characters of text, and OCR off or not done), `GARBLED_TEXT` (a PDF whose only characters are private-use or replacement ones), `NO_TEXT` (a DOCX without text), `NO_TEXT_FOUND` (OCR found no text), `BLANK` (a blank page or image), `OCR_NOT_DONE` (an image left by a limit), `OCR_OFF` (an image with OCR off), `IMAGE_TOO_LARGE`, `UNSUPPORTED_IMAGE` (TIFF, HEIC, AVIF, GIF, BMP), AI errors (`AI_UNAVAILABLE`, `RATE_LIMITED`, `AI_REFUSED`, `AI_BAD_FORMAT` (an answer twice without the required marker line), `AI_OUTPUT_TOO_LONG`, `AI_AUTH_FAILED`, `AI_ACCOUNT_LIMIT`, `AI_FORBIDDEN`), drawing errors (`RENDER_FAILED`, `RENDER_TIMEOUT`), `ENCRYPTED`, `CORRUPT_FILE`, `TOO_MANY_PAGES`, `NO_PAGES_IN_RANGE`, `FILE_TOO_LARGE`, `TOO_LARGE`, `TOO_MANY_ENTRIES`, `TOO_LARGE_FOR_MEMORY`, `TIMEOUT`, `UNSUPPORTED_FORMAT`, `NOT_A_DOCUMENT`, `READ_FAILED`, `EXTRACTION_FAILED` and, for links, `NOT_FOUND`, `AUTH_REQUIRED`, `RATE_LIMITED`, `HTTP_ERROR`, `BLOCKED_ADDRESS`, `BLOCKED_URL`, `DNS_FAILED`, `DOWNLOAD_FAILED`, `SLOW_DOWNLOAD`, `TOO_MANY_REDIRECTS`.

The run's key-value store has the summary in `OUTPUT`: status (`COMPLETE`, `PARTIAL`, `FAILED`), counts of extracted, no-text, failed and skipped files, PDF pages read, characters, rows, `chargedEvents` and `chargedOcrEvents`, OCR counts (`ocr`) and the AI's use (`aiUsage`: requests, tokens, and the cost OpenRouter reported). It is written at the start and after every file, so it also exists when a run is stopped. While a file is read with OCR, two small records (`OCR-SENT`, `OCR-000001` ...) let a moved run go on without sending pages again; the second is removed after each file.

### Run it after another Actor

If another Actor saves PDF, DOCX or image files in its key-value store, add this Actor in that Actor's **Integrations** tab and set the input field to the other run's store:

```json
{ "keyValueStoreId": "{{resource.defaultKeyValueStoreId}}", "splitBy": "page" }
```

Set `keyValueStoreId` like this; a store that comes only in the integration's payload cannot be read under limited permissions, and the run stops before anything is charged with a message that says so. With OCR on, the images in that store are read too (and charged per OCR page); set `ocr: "off"` to read only PDF and DOCX files.

### Pricing

The prices are on the **Pricing** tab of this Actor. This Actor uses pay-per-event pricing:

| Event | When | FREE | BRONZE | SILVER | GOLD and above |
|---|---|---|---|---|---|
| `document-extracted` | Per started 20 PDF pages whose text came from the text layer, or per started 50,000 characters of a DOCX | $0.003 | $0.0027 | $0.0024 | $0.0021 |
| Per 1,000 events | | $3.00 | $2.70 | $2.40 | $2.10 |
| `page-ocr` | Per OCR page whose OCR gave text: a PDF page, an image up to about 2,000 x 2,800 px, or one part (up to 2,800 px) of a taller page or image | $0.004 | $0.0036 | $0.0032 | $0.0028 |
| Per 1,000 events | | $4.00 | $3.60 | $3.20 | $2.80 |
| `apify-actor-start` (Apify) | Every run, also the samples: once per GB of memory (the default 1 GB = once) | $0.00005 | $0.00005 | $0.00005 | $0.00005 |

The tier comes from your Apify plan, and your own price is shown on the Pricing tab. The start event has no tiers. Examples at the FREE price: a 1-page or 20-page text PDF $0.003, a 100-page text PDF $0.015, a 10-page scan $0.04, a 40-page PDF with text on 20 pages and scans on the others $0.003 + $0.08 = $0.083, a photo of a receipt or a phone screenshot (up to about 2,000 x 2,800 px) $0.004, a long screenshot of 1,080 x 6,000 px cut into 3 parts $0.012.

**The AI model is billed separately.** OCR sends page pictures to Google Gemini 3.1 Flash-Lite through Apify's official OpenRouter Actor (`apify/openrouter`). Apify charges that model use to your own Apify account, in a separate run of `apify/openrouter`, at OpenRouter's price rounded up to $0.00001, without any markup from this Actor: about **$0.0005-0.002 per page** on paid Apify plans (more for dense pages), and **about 10 times that on the Free plan** ($0.005-0.02 per page). Each run with OCR also starts one `apify/openrouter` run (about $0.0023 measured on the Free plan; about $0.0013 estimated on paid plans). `OUTPUT.aiUsage.costUsd` shows the cost OpenRouter reported for the run. A page whose OCR fails is not charged by this Actor, but the AI cost of trying may already be charged. **Your maximum cost per run limits this Actor's events only, not the AI bill**: that is what `maxOcrPages` is for (200 pages per run on a paid plan, 20 on the Free plan, when you leave it empty; resends after errors never pass twice that number).

- **Not charged**: the built-in samples, failed files (password-protected, damaged, not a supported format, too large, a link that fails), `no-text` documents, blank pages, pages the OCR could not read, pages left by `maxOcrPages` or the maximum cost, text that looks garbled (`garbledSuspected: true`, kept as it is; see the [FAQ](#faq)), and the runs that stop at the input checks.
- **Maximum cost per run**: before a page is sent to the AI, the rest of your limit must cover one more `page-ocr` for each of its parts (on top of the pages in flight), so nobody pays the AI for a page this Actor could not deliver. When it does not, OCR stops there, the document's row says how many pages were left, and the run stops with status `PARTIAL`; the document's text-layer pages are in its row, and only the `document-extracted` events that still fit are charged. A text PDF whose pages the limit does not cover is not read. A new run starts from the first file again.
- **Unpaid time**: files that fail or have no text earn nothing, so after about 10 minutes of such run time at 1 GB (more for every event charged) the rest of the run is not read; drawing pages for OCR that turn out blank or cannot be read counts too, also inside one long file.
- **No double charges**: each document is charged right after its rows are saved. If Apify moves the run to another server, or a run that failed is resurrected, it goes on after the last saved file and does not read or charge the earlier files again; OCR pages already read for the file in work are not sent to the AI again.

### Limits

Measured on Apify with the default 1 GB of memory (version 0.1, text layer only), one file per run read from a key-value store (run time from start to end; reading = loading the file, starting the reader and extracting; peak memory as Apify reports it):

| File | Run time | Reading | Peak memory | Events |
|---|---|---|---|---|
| 200-page Japanese PDF (the sample's pages repeated, 1.7 MB) | 3.4 s | 1.8 s | 110 MB | 10 |
| 2,000-page Japanese PDF (17.7 MB) | 10.3 s | 8.8 s | 241 MB | 100 |
| 2,000-page English text PDF, 40 lines per page (7.9 MB, 5.3 million characters) | 6.3 s | 4.8 s | 194 MB | 100 |
| 50 pages, each a 532 KB photo and two lines of text (25.4 MB) | 1.9 s | 1.0 s | 122 MB | 3 |
| 200 pages that are only pictures, like a scan (37.6 MB, OCR off) | 1.7 s | 0.9 s | 143 MB | 0 (`no-text`) |

OCR on Apify (build 0.2.1, 1 GB): a 6-page scan (English, Japanese, vertical Japanese, a table, one blank page) and a 1,080 x 6,000 px PNG in one run took 10.7 s with a peak of 169 MB. Locally (Windows), drawing one A4 page takes about 0.1-0.6 s. The built-in samples take a few seconds for the whole run.

Memory: a PDF with very much text per page needs more than the default 1 GB. Measured locally: 2,000 pages of 80 English lines each (17.6 MB, about 13 million characters) fail with `TOO_LARGE_FOR_MEMORY` at 1 GB and read with `pages: 1-1000`, or with 2 GB. On Apify with 2 GB, such a PDF read in 11.3 s with a peak of 484 MB. One file may give at most about 33 million characters at 1 GB (more with more memory). Drawing a scanned page for OCR needs more memory the finer it was scanned, because the page picture is unpacked at its own size first. Measured locally with 1 GB (A4 scans): 300 dpi about 160 MB more, 400 dpi about 243 MB, 600 dpi about 585 MB, which does not fit in 1 GB: **give 2 GB to scans of 600 dpi**. A page that would pass 60% of the run's memory fails with `TOO_LARGE_FOR_MEMORY` (not charged), and the row names the memory to choose.

Fixed limits: 100 MB per file; images 25 MB and 60 megapixels; 2,000 pages read per PDF (choose more with several runs and `pages`); 120 seconds per file for the text layer, 60 seconds per page drawn for OCR; 100 links per run; OCR pages per run as set by `maxOcrPages` (at most 5,000); 40 parts of at most 2,800 px per page or image (the rest is not read; a PDF page is drawn on at most 36 megapixels from its top); for DOCX, 200 MB of unpacked text parts and 10,000 parts in the file. The memory check needs about 3 times the file size plus 100 MB (for an image, about 5 bytes per pixel plus 100 MB); a file that does not fit fails with `TOO_LARGE_FOR_MEMORY` and the memory to choose.

What the extraction does not do:

- **OCR is done by an AI model**, which can misread text, like any OCR: check important numbers. It is told to output only the text and never to translate or complete it. Handwriting, very small print and low-quality photos read worse. Pages of a PDF whose text layer is fine are not OCR'd in `auto` mode.
- **Images**: PNG, JPEG and WebP only (TIFF, HEIC, AVIF, GIF and BMP fail with `UNSUPPORTED_IMAGE`: save them as PNG or JPEG, or put the pages in a PDF). A JPEG photo's EXIF rotation may not be applied; the model reads rotated text in most cases.
- **Reading order** of the text layer follows the order of the text in the file. Most PDFs store it in reading order; PDFs with complex layouts (several columns, text boxes) may come out in another order. Tables in PDFs become lines with the cells separated by spaces (by OCR: Markdown tables or tab-separated cells).
- **Mixed documents**: in a PDF with OCR pages, the pages are joined with an empty line between them, so a paragraph that goes on from one page to the next is not joined across the pages (also between two text-layer pages of such a PDF).
- **Headers and footers** are found among the text-layer pages read: they need 3 pages or more (page numbers: 2 pages or more). OCR pages keep their headers and page numbers as the AI reads them. Headers, footers, footnotes and comments of a DOCX are not read.
- **Drawings**: a PDF of plans or maps whose drawing instructions unpack to hundreds of megabytes can stop at the memory limit even when the file is small.
- Password-protected files are not opened. Old `.doc` files, PowerPoint and Excel files are not read in this version. DOCX files are never OCR'd (pictures inside a Word file are not read).

### Privacy

- Files are read inside the run and the text is written only to the run's dataset. Nothing is kept anywhere else, and the Actor reads only the stores you choose (limited permissions).
- **With OCR, page pictures are sent to an AI model**: the pages that need OCR (or every page with `ocr: always`) and images are sent as JPEG pictures, with fixed instructions, to Google Gemini 3.1 Flash-Lite (or, when OpenRouter has no endpoint for it, Gemini 3.5 Flash-Lite) through OpenRouter, via Apify's official `apify/openrouter` Actor, with this run's own Apify token. Nothing else of yours (no file names, links or text layers) is sent. OpenRouter and the model provider handle these pictures under their own terms. **With `ocr: "off"` nothing is sent to any AI.**
- Links appear in rows and logs without their query string. `OUTPUT` keeps a short hash of the list of links (to continue after a migration), not the list itself; it has no salt, so someone who can guess the exact list could check a guess against it. The reason of the first link that failed, which can show that link without its query string, is in `OUTPUT` too (`resume.firstUrlError`). While a file is read with OCR, the text of the pages read so far is kept in the run's own key-value store (`OCR-000001` ...) until the file's rows are saved, so a moved run does not send them again.

### FAQ

**Does PDF Text Extractor read scanned PDFs?** Yes, with OCR (the default `ocr: auto`). A scan (fewer than 10 characters of text in all) is read page by page by the AI model and charged per OCR page with text; in a PDF where half or more of the pages have no text, only those pages are OCR'd and the others keep their text layer. With `ocr: off` a scan comes back as `no-text` with `needsOcr: true` and is not charged, as in version 0.1.

**What does OCR cost in total?** On a paid Apify plan, about $0.0045-0.006 per page: $0.004 for `page-ocr` (FREE tier) plus about $0.0005-0.002 that `apify/openrouter` bills for the AI model. On the Free plan the AI part is about 10 times higher. Blank pages are neither sent nor charged.

**What does garbledSuspected mean?** Some PDFs use fonts that do not say which letters they draw; their "text" comes out as runs of punctuation or a mix of alphabets inside one word. When most pages of a PDF look like that, the row says `garbledSuspected: true`: the text is still returned but not charged, and `ocrNote` suggests `ocr: always` to read those pages by OCR instead (in `auto` mode they are not OCR'd automatically, because the detection is best-effort and OCR costs money). A PDF whose characters are all unreadable (`GARBLED_TEXT`) is OCR'd in `auto` mode.

**Why are there no spaces between Japanese characters?** Japanese is written without spaces between words, and PDFs often put small gaps between characters. PDF Text Extractor never adds a space between kanji, kana or Japanese punctuation, also where it joins wrapped lines, and the OCR instructions ask for the same. Spaces between English words stay.

**Does PDF Text Extractor read vertical Japanese text (tategaki)?** Yes. Vertical columns in the text layer are read top to bottom and right to left, and `verticalTextPages` counts those pages; OCR is told to read vertical text the same way.

**How are headers and page numbers found?** At the top or bottom of a text-layer page: a decorated page number (`- 12 -`, `Page 3 of 10`, `第3頁`) is removed; a bare number (`12`) only when it goes up with the page, so a year or an amount stays; a line that repeats on at least half of the pages is removed when its only changing number goes up with the page (`Annual Report 2026 p.3`). A line that is exactly the same at the top (or bottom) of at least half of the pages, and of 3 pages or more, stays on the first page where it appears and is removed from the others. A fixed heading at the top of every page in the body text's size, such as `Question 1`, `Question 2` ... one per page, looks like a page header and is removed: turn this off with `removeHeadersFooters: false`.

**Are files stored?** No. They are read inside the run; only the extracted text goes into the run's dataset (and, while a file is read with OCR, the pages read so far into the run's own key-value store).

### More from Quiet Works Lab

- [Audio & Video to Text - Transcribe to SRT, VTT & JSON](https://apify.com/quietworkslab/audio-video-to-text): transcribe audio and video files to text, SRT or WebVTT subtitles and timestamped JSON segments.
- [Dataset Diff - Only New & Changed Items Since Last Run](https://apify.com/quietworkslab/dataset-change-tracker): get only the new and changed items since your scraper's last run, or compare two datasets.
- [Image Converter & Compressor - WebP, AVIF, strip EXIF/GPS](https://apify.com/quietworkslab/image-converter): convert and compress images and remove EXIF, GPS and other metadata.
- [Japanese Text Normalizer & RAG Chunker](https://apify.com/quietworkslab/japanese-text-normalizer): clean Japanese text before an LLM or RAG and split it into sentence-aware chunks; the `japanese` clean-up here is the same.
- [Merge, Deduplicate & Join Datasets](https://apify.com/quietworkslab/merge-dedup-datasets): merge your datasets, remove duplicates by key and join fields from a lookup dataset.
- [Video Frame Extractor - Thumbnails, Scenes & Contact Sheet](https://apify.com/quietworkslab/video-frame-extractor): extract thumbnails and frames from your videos, with a contact sheet per video.

### Support

Report a problem in the **Issues** tab: the input you used (without private links) and the run ID help most. Files that come out wrong are welcome as examples, if you may share them.

This Actor is developed and maintained with the help of AI (Claude Code). Issues are answered within a few days.

The sample PDFs embed characters of Noto Sans JP (SIL Open Font License 1.1, license in `sample/LICENSE-NotoSansJP-OFL.txt`).

### 日本語の概要

PDF と Word（DOCX）のファイルから、きれいなテキストを取り出します。スキャンした PDF と画像（PNG・JPEG・WebP）は OCR で読み取ります。ファイルの直接のリンク、Apify のキー・バリュー・ストア、アップロードから読めます。折り返しの改行を段落にまとめ（漢字・かなの間に空白を入れません）、ヘッダー・フッター・ページ番号を取り除き、縦書きは右の列から読みます。料金は文字の層のある PDF 20ページ（DOCX は5万字）ごとに $0.003、OCR 1ページ $0.004（FREE の価格）。OCR の AI（Google Gemini 3.1 Flash-Lite、Apify 公式の apify/openrouter 経由）の代金は、別に Apify のアカウントに付きます（有料プランで1ページ約 $0.0005〜0.002、無料プランは約10倍）。OCR ではページの画像が AI に送られます。`ocr: "off"` なら何も送りません。見本・失敗したファイル・白紙のページ・読めなかったページには、この Actor の料金はかかりません（Apify の開始の料金は別）。

# Changelog

This Actor's version history is a separate document: https://apify.com/quietworkslab/pdf-text-extractor/changelog.md

# Actor input Schema

## `fileUrls` (type: `array`):

Direct links to PDF, DOCX, PNG, JPEG or WebP files (not web pages); use only files you have the right to use. A run takes up to 100 links, read one at a time after the store and the uploads. A link that fails is not charged. Leave empty (with no store and no uploads) to try the Actor on built-in sample files.

## `keyValueStoreId` (type: `string`):

Optional. A key-value store in your account that holds PDF, DOCX or image files. Every record that is a PDF or DOCX is read, and with OCR on (the default) every PNG, JPEG or WebP image too; JSON and other records are skipped. When this Actor runs after another Actor from its Integrations tab, set it to {{resource.defaultKeyValueStoreId}}. Uploaded files that are in this store are read with it, once.

## `keyPrefix` (type: `string`):

Optional. Read only the records of the key-value store whose key starts with this text, for example invoice- or 2026-11-. Empty = all records.

## `uploadedFiles` (type: `array`):

Optional. Upload PDF or DOCX files (up to 100 MB each) or PNG, JPEG or WebP images (up to 25 MB) here. This field takes only files stored in your Apify account; put links to files on other websites into "File links". If your account keeps its storages private (the default), the run names the store your uploads are in: choose that store in "Key-value store" and start again.

## `pages` (type: `string`):

Optional. Which pages of each PDF to read, for example 1-5,10 or 20- (from page 20 to the end). Empty = all pages (up to 2,000 per file). Only the pages read that have text are counted. DOCX files have no pages and are read whole.

## `splitBy` (type: `string`):

Document: one dataset row per file. Page: one row per PDF page (handy for search and RAG); a DOCX file is still one row. The rows have the same fields either way.

## `lineJoin` (type: `string`):

Join wrapped lines into paragraphs (default): lines that the layout wrapped are joined, with no space between Japanese characters, and an English word split by a hyphen at the end of a line is mended; OCR text the same way (table rows, list items and headings stay on their own lines). Keep: every line stays a line, as on the page.

## `removeHeadersFooters` (type: `boolean`):

Checked (default): at the top or bottom of a page, page numbers are removed (a bare number only when it goes up with the page; documents of 2 pages or more), and so is a line that differs only in a number that goes up with the page on at least half of the pages; a line that is exactly the same on at least half of the pages (documents of 3 pages or more) stays on the first page where it appears and is removed from the others. Headings in a bigger font, sentences and amounts that differ by page stay. The count is in removedLines.

## `normalize` (type: `string`):

Basic: invisible and control characters removed, spaces tidied, Unicode NFC. Japanese: also full-width letters and digits to ASCII, half-width katakana to full width, dashes and long vowels fixed (the same clean-up as Japanese Text Normalizer by Quiet Works Lab). None: the text as extracted.

## `outputFormat` (type: `string`):

Plain text: paragraphs separated by an empty line. Markdown: a simple version; PDF headings are guessed from a bigger font size, DOCX headings, lists and tables come from the document.

## `maxFiles` (type: `integer`):

Optional. Stop after this many files (extracted, without text, or failed), for example to try the settings on 5 files first. Empty = no limit.

## `ocr` (type: `string`):

Auto (default): pages of a PDF without a usable text layer (a scan, a garbled font, or mostly empty pages) and images are read by an AI model (Google Gemini 3.1 Flash-Lite through Apify's apify/openrouter Actor); the other pages keep their text layer. Always: every PDF page is read by the AI. Off: version 0.1 behaviour, scans are flagged and not charged, and nothing is sent to any AI. One page-ocr event per OCR page with text; the AI model is billed separately to your Apify account by apify/openrouter at its own price. DOCX files are never OCR'd.

## `maxOcrPages` (type: `integer`):

Optional. The most OCR pages sent to the AI in one run: a PDF page or an image up to about 2,000 x 2,800 pixels is one, a long screenshot is cut into several. The rest is not OCR'd and the rows say so. Empty = 200 on a paid Apify plan, 20 on the Free plan (where the AI costs 10 times more). Resends never pass twice this number. Your maximum cost per run limits this Actor's events only, not the AI bill, so this cap is what limits the AI cost.

## Actor input object example

```json
{
  "splitBy": "document",
  "lineJoin": "smart",
  "removeHeadersFooters": true,
  "normalize": "basic",
  "outputFormat": "text",
  "ocr": "auto"
}
```

# Actor output Schema

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

One row per document, image or PDF page: status, text, text source (text layer or OCR), pages, OCR pages, character count, needsOcr and document information.

## `summary` (type: `string`):

Status, settings, counts and AI usage of the run (record OUTPUT). It is written at the start and after every file, so it also exists when a run is stopped by a timeout or lack of memory (status RUNNING).

# 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 = {};

// Run the Actor and wait for it to finish
const run = await client.actor("quietworkslab/pdf-text-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 = {}

# Run the Actor and wait for it to finish
run = client.actor("quietworkslab/pdf-text-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 '{}' |
apify call quietworkslab/pdf-text-extractor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,quietworkslab/pdf-text-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/Qh4H56VZ5C6MKkaEv/builds/uq4ioQp6463EWUvyS/openapi.json
