# PDF to Text and Markdown: Clean Text for RAG (`bardach_technologies/pdf-to-clean-text-and-markdown`) Actor

PDF to text and PDF to Markdown for RAG and LLM input: extract text from PDF files (URLs or stored keys) in reading order for one- and two-column pages, running headers, footers and page numbers removed, split words rejoined. Not for scanned PDFs (no OCR). USD 0.30 per 1,000 pages.

- **URL**: https://apify.com/bardach_technologies/pdf-to-clean-text-and-markdown.md
- **Developed by:** [Bardach Technologies](https://apify.com/bardach_technologies) (community)
- **Categories:** AI, Developer tools, Automation
- **Features:** Limited permissions
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.30 / 1,000 pages of text extracted

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

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 and Markdown** extractor for **RAG** and LLM input (PDF to text, PDF to Markdown): give it PDF URLs or stored PDF files and get **clean text** per page and per document, in reading order, with **running headers, footers and page numbers removed** and words split at line ends joined again. Every removed line is listed, so you can check what was taken out. Text PDFs only (no OCR). **USD 0.30 per 1,000 pages with a text layer** (pay per event; scans, failed and protected PDFs are free). To try it, start it with the prefilled sample PDF: 3 pages, no website needed, USD 0.00095.

**Use it when**

- you want to extract text from PDF files (reports, papers, manuals, filings) as plain text or Markdown for an LLM, a RAG index or search;
- page furniture (a running title on every page, "Page 7 of 20", a confidential footer) must not end up in every chunk;
- two-column papers must read left column first, then right column, instead of line by line across the page.

### Do not use it when

- the PDF is a scan or a photo of pages: there is no OCR, such PDFs are reported as `no_text_layer` and not charged;
- you need the tables as rows and columns (this Actor gives table rows as lines of text, not cells);
- the layout has three or more columns, text in boxes around the page, or right-to-left scripts: reading order is only worked out for one and two columns;
- the PDF needs a password to open: such PDFs are reported as `password_required` and not read (a PDF with only an owner password, which opens without one and only carries permission flags, is read like any other).

Minimal input (the sample run uses `{"samplePdf": true}` instead):

```json
{"pdfUrls": ["https://www.example.com/annual-report.pdf"], "outputFormat": "markdown"}
```

One output row, as the prefilled sample run gave it on Apify on 2026-11-18 (the page row of page 2; `text` left out and `markdown` cut at the three dots; every PDF also gets one document row with the whole text):

```json
{"recordType": "page", "sourceIndex": 0, "source": "sample:built-in", "page": 2, "hasText": true, "columns": 2, "markdown": "# Two columns\n\nAlpha one starts the left column and runs down the page for a while, then alpha two continues the same ...", "charCount": 491, "removedLines": [{"band": "header", "text": "Harbour Works Annual Notes - sample document", "reason": "repeated"}, {"band": "footer", "text": "Sample made for this Actor; all text is invented", "reason": "repeated"}, {"band": "footer", "text": "Page 2 of 3", "reason": "repeated"}]}
```

**Cost in plain words:** USD 0.0003 per page with a text layer that is written to the dataset (USD 0.30 per 1,000 pages), plus Apify's start event of USD 0.00005 per run. The prefilled 3-page sample costs USD 0.00095; a 478-page text PDF costs about USD 0.14. Measured on the Apify platform on 2026-11-18 at 1024 MB memory: the prefilled 3-page sample took 3.3 seconds; a 486-page statute (478 pages with text) took 187 seconds, and 51 seconds at 4096 MB.

### How to convert PDF to clean text or Markdown

1. Open the Actor on Apify. The form is prefilled with the built-in sample PDF, so a first run needs nothing else.
2. For your own files, paste the PDF URLs under `pdfUrls` (one per line), or upload PDFs to a key-value store, pick that store under 'Key-value store' (`keyValueStoreId`) and list their keys under `pdfKeys`.
3. Choose `outputFormat` (`text`, `markdown` or `both`) and, if you only need part of a file, a page range such as `1-3,5,8-`.
4. Start the run. The dataset holds one row per page and then one row per PDF with the whole text; `removedLines` shows every header, footer and page number that was taken out.
5. To run it from your own code or at regular intervals, use the Apify API, a recurring run, a webhook or an integration from the Actor's page; the same input JSON works everywhere.

### Use cases

- **RAG and search indexes**: page rows are ready-made chunks without the running title and page number in each of them.
- **LLM input**: summarise or question reports, filings, laws, manuals and papers without paying tokens for repeated page furniture.
- **Two-column papers**: text in reading order, left column before right column, with split words joined.
- **Document pipelines**: one row per PDF with status, page counts and warnings, so a failed, protected or scanned file is reported instead of silently missing.
- **Auditable cleaning**: every removed line is listed with its page, band and reason, and one switch keeps everything.

### Sample output table

The one-click default run (the built-in 3-page sample PDF; 26.11.2026) wrote 4 rows (3 page rows and 1 document row) and cost USD 0.0009 (3 x 0.0003) plus Apify's start fee (USD 0.00095 in total). The document row says 3 pages read, 3 with text, 186 words, 1,068 characters. The page rows:

| page | columns | charCount | first Markdown line | header or footer lines removed |
|---|---|---|---|---|
| 1 | 1 | 283 | # Introduction | 2 |
| 2 | 2 | 491 | # Two columns | 3 |
| 3 | 1 | 290 | # Closing notes | 2 |

### Input

| Field | Default | What it does |
|---|---|---|
| `pdfUrls` | none | Public http(s) URLs of PDFs, up to 50 PDFs per run in all, each at most 50 MB |
| `pdfKeys`, `keyValueStoreId` | none | PDFs stored in a key-value store (this run's own store, or one you pick in the field 'Key-value store' or pass by its ID; it is only read) |
| `samplePdf` | off (the form prefill ticks it) | Reads the built-in 3-page sample |
| `pages`, `maxPagesPerPdf` | all pages, 500 | Page range such as `1-3,5,8-`; at most 500 pages per PDF |
| `outputFormat` | `both` | `text`, `markdown` or `both` |
| `includePageRows` | on | One row per page before each PDF's document row |
| `stripRepeatedLines`, `minRepeatPercent` | on, 60 | Remove running headers, footers and page numbers; how often a line must repeat |
| `joinHyphenation` | on | Join words split at a line end |
| `timeoutSecPerPdf` | 300 | Stop reading one PDF after this many seconds (10 to 900) and return the pages read |

With no source at all the run ends at once with a summary and no rows.

### Output

For every PDF, in input order:

- one **page row** per page read (switch off with `includePageRows`): page number, `text` and/or `markdown`, `hasText`, `columns` (1 or 2), `truncated` (the page's text was cut at a per-page limit, see Limits), `removedLines`;
- then one **document row**: `status`, `reason`, page counts, the whole document's `text` and/or `markdown` (paragraphs flow across page and column breaks), every removed line with its page, band and reason, `chargedPages`, `wordCount`, `warnings`. A document too large for one dataset row (over 8 MB) keeps its text in the key-value store (`textKey`, `textUrl`, `markdownKey`, `markdownUrl`).

The run summary is the `OUTPUT` record: `outcome` is `complete` (every PDF read in full), `incomplete` (some PDF failed, was skipped, had no text layer, was stopped at a limit or cut at the page limit) or `stoppedEarly` (your maximum charge was reached; what was written is complete and charged).

Statuses of a document row: `processed`, `partial` (stopped at the time, memory or CPU limit: the pages read before the stop are returned, nothing after them), `no_text_layer`, `failed`, `password_required`, `skipped_robots`, `blocked_unsafe`, `skipped_refused` (the URL's host refused an earlier request of this run with HTTP 401, 403, 407, 429 or 451, answered it with a bot challenge, or its robots.txt refused with one of those codes, so this URL was not requested). Only `processed` and `partial` count pages for the price (`chargedPages`), and only pages with text that were not cut (`truncated`): USD 0.0003 each. `source` is the entered link or key as it may be shown: a link keeps scheme, host and path, without query, fragment or login, and a link or key that holds an e-mail address or a phone number (`+` and 8 to 15 digits, `tel:`, `mailto:`, `wa.me`) is shown as `<scheme>://<host>/[removed]` when the contact is in the path, and as `<scheme>://[removed]/[removed]` when the contact is in the host name (a key is masked in the same way; percent-encoding is read up to 8 times, so a contact hidden under more rounds of encoding is not found); the real link is the one requested. `sourceKey` (document rows) is a hash of the entered link or key, which a restart compares instead of the shown text. The text of your PDFs is delivered as written and is not masked. `finalHost` is the host name the PDF came from after redirects (a host name that holds a contact is shown as `[removed]` there, as in the reasons of a failed or refused row); the path and query of a redirect target are never written (a signed storage link carries its credentials there). A PDF whose rows cannot be written to the dataset gets one free `failed` row instead and the run goes on; if the dataset refuses a write after some of its page rows were written, those rows stay, their pages are charged and a `partial` document row says how many were written (without the document text). If even that row cannot be written, the run stops with the error.

### How the text is cleaned

1. **Text layer only.** Upright characters on the visible page are read with pdfminer.six through pdfplumber. Sideways text (margin stamps), text outside the page and glyphs without a character mapping are dropped and counted. No OCR.
2. **Reading order.** Words become lines; a page is two-column when a vertical gap in the middle 30 to 70 % of the text block has at least 5 lines of 4 or more words on each side that fill most of their column. Full-width lines (titles, captions) stay in place; between them the left column is read before the right column. Otherwise the page is one column, top to bottom. Pieces of a word that touch are one word: in the same font size, or in small capitals (a full-size initial followed by smaller capitals on the same baseline, so "JUSTICE" is not split into "J USTICE"); a smaller index in a formula keeps its space.
3. **Headers, footers and page numbers.** A line is a candidate only when it **stands apart from the page's text block**: walking in from the top edge and from the bottom edge, rows of at most two lines that are followed by a gap larger than the page's usual line spacing plus 0.6 font sizes are set apart, up to three such groups within the outer quarter of the page, as long as some text is left between them. A line that repeats but sits in the text block at its normal line spacing (a table's column header repeated on every page, a section title right above the text, a last line "Confidential") is not a candidate and stays. A candidate is removed when:
   - `repeated`: its text, digits and spaces ignored, is on at least 60 % of the pages with text (`minRepeatPercent`, 30 to 100) and on at least 3 pages; or, in the outer 10 % of the page or in a place the heads take on most pages, on 60 % of the odd or of the even pages and under 40 % of the others (book style). A copy set 1.3 times larger than usual (a paper's title on page 1 that is also its running head) stays, and outside the outer 10 % of the page a line set as a heading (1.15 times the body size or larger) is never removed for repeating;
   - `repeatedInSection`: it is a line of its own, set smaller than the body text (at most 0.9 times its size), in a place that lines set apart take on most pages, and the same words repeat there on at least 60 % of the pages from its first to its last page and on at least 3 pages: a running head that changes per chapter, part or section;
   - `runningHeadSlot`: such a small line of its own in a place where most of these lines were found to be running heads (a section's head that is on one page only);
   - `pageNumber`: it is only a page number (7, - 7 -, 7 / 20, Page 7, Page 7 of 20, p. 7, vii) that follows the page order;
   - `runningHeadWithPageNumber`: a page number that follows the page order next to a title seen on at least 2 pages, or in the place where running heads were found on at least 3 pages.
     Lines in the outer 10 % that are close to the text are removed only as page numbers or as a copy of a running head that stands apart on other pages in the same place. Every removed line is listed in `removedLines` with its band, text and reason; set `stripRepeatedLines` to false to keep everything.
4. **Split words.** "infor-" + "mation" becomes "information"; the hyphen stays when the next part starts with a capital or a digit (COVID-19), when the document itself writes the hyphenated word (well-known), or when the next part holds a hyphen itself (state- + of-the-art becomes state-of-the-art). A suspended hyphen before und, oder, and, or, nor, bzw., sowie or & keeps the hyphen and the space ("Post- und Fernmeldewesen", "pre- and post-processing"). Soft hyphens are removed.
5. **Paragraphs and Markdown.** A line joins the paragraph above when that line reached its column's right edge (or the next word would not have fitted after it) and the gap is small; a jump to the next column or page continues a paragraph the same way. A first line indented by 0.8 to 8 font sizes against the line above, followed by a line back at the left edge, starts a new paragraph even after a full line; a hanging indent (all lines after the first set in) does not. Lines 1.15 times the body font size or larger are headings (`#` from 1.6 times, `##` from 1.3, `###` below); bullet lines become `- ` items.

### Limits

- Up to 50 PDFs per run (URLs, keys and the sample together), each file at most 50 MB, at most 500 pages per PDF (`maxPagesPerPdf`).
- Per page at most 20,000 words, 2,000 lines and 512 KB of text (UTF-8), and a page row stays under 8 MB: a page over one of these is cut, its row says `truncated: true`, and it is not counted for the price. Per PDF at most 16 MB of text: reading stops at the page that would pass it (the document row's warnings say so).
- CPU budget per PDF: 20 CPU seconds plus 0.5 per page asked for (`maxPagesPerPdf`), never more than `timeoutSecPerPdf`, and 15 CPU seconds per page. A normal page needs well under a second (about 0.1 measured on the platform). A PDF or page over its budget is stopped like at the time limit: the pages read before are returned (`partial`), or the PDF is `failed` when there are none. Every encoded stream (Flate, LZW, RunLength, ASCII85, ASCIIHex, fax) may expand to at most 64 MB; image data is never decoded.
- Reading one PDF stops after `timeoutSecPerPdf` (10 to 900 seconds, default 300); the pages read before the stop are returned (`partial`). Putting the text together afterwards has its own time, counted from the end of reading: the same limit plus 10 seconds, so a PDF read up to its limit still gets as long for this step as the reading had; a PDF whose text step needs longer than that gets a free `failed` row whose reason starts with `timeout:`. A download has its own 60-second limit.
- No OCR; no passwords; no tables as cells; one or two columns only.
- A real line that is set apart near the top or bottom of most pages (a document title not set larger than the text, in the outer 10 % above the text of every page; "(Continued)" under continued tables) is removed as a running head; so is a small line set apart on its own in the running-head place over a stretch of pages. Such lines are listed in `removedLines`, and `stripRepeatedLines: false` keeps them.
- Not found: a running head in the body font size that is on only part of the document (a date at the top of the text pages of a report with many table pages), a head that is close to the text on a page with wide line spacing, and a running head that changes per chapter when it is set as large as the body text and carries no page number.
- The rules are heuristics: unusual layouts (sidebars, pull quotes, text in boxes) can be read in the wrong order.
- Two printed pages on one PDF page (a booklet spread): each half is read as a column, but the pair of page numbers under them ("6 7") is not removed.
- A real compound split at a line end loses its hyphen when the document never writes it inside a line (about 1 in 100 joined words in the files read by hand).
- A scanned PDF still gets one page row per page (`hasText` false, empty text) and its document row.
- The words "charged" and `chargedPages` in messages and rows mean "counted for the price" (USD 0.0003 per page).
- Speed, measured on the Apify platform on 2026-11-18 with a 486-page text PDF: about 2.8 pages per second at 1024 MB and about 10.8 pages per second at 4096 MB. At 1024 MB that file needed 174 seconds; the default limit is 300 seconds per PDF, about 840 pages' worth at that speed. A slower PDF that runs out of time comes back as `partial` with the pages read; for such files raise `timeoutSecPerPdf` or the run's memory.
- Pay per event has not yet run on the platform for this Actor: charging, the maximum-charge stop and "no page charged twice after a resume" were tested only with the SDK's local simulation.

### Safety

- Only the URLs you list are requested (and their redirects, at most 5). For every request the host is resolved first and every address must be public (no private, loopback, link-local, multicast, reserved, cloud-metadata or IPv4-in-IPv6 addresses); only then is robots.txt asked, and a URL it does not allow is skipped (`skipped_robots`); so is a URL whose robots.txt cannot be read (a network error, a server error or too many requests), and the reason says which of the two it was. A PDF host that answers 401, 403, 407, 429 or 451, or a bot challenge (recognised by the answer's structure: a `cf-mitigated` or AWS WAF challenge header, or a 202 web page where a PDF was asked), and a host whose robots.txt answers one of those codes, or with a bot challenge or a web page instead of the text file, is not asked again in the run, also after a restart (not even for robots.txt): its remaining URLs get free `skipped_refused` rows without a request. robots.txt is asked only on the host you entered; a redirect of robots.txt is followed only to the same host or its www twin, and a redirect of a PDF to another host is followed without asking that host's robots.txt. An address written in a non-standard numeric form (127.1, 0177.0.0.1, 2130706433) is refused. At most one request per second per host, the robots.txt request included, a generic user agent, no cookies, no compressed transfers, a size cap while streaming.
- Each PDF is read in a separate process that is killed at the time limit or at its memory limit and gets no tokens or other secrets. Nothing in a PDF is executed (no JavaScript, no launch actions, no embedded files are opened); compression bombs are refused.
- Resume: after a crash or migration the run checks its own output (counts and a hash chain) and continues after the last complete PDF; a page is never charged twice. A write cut off in the middle is refused with a clear message instead of guessed.

### Pricing

Pay per event: **USD 0.0003 per page with a text layer** that is written to the dataset (USD 0.30 per 1,000 pages), event `page-processed`, charged right after the PDF's rows are written, plus Apify's start event (USD 0.00005 per run). Pages without a text layer (scans), failed, password-protected, robots-skipped or blocked PDFs, and pages not written because your maximum charge was reached are free. A PDF stopped at its time or memory limit is charged only for the pages it returned.

**Cost examples:** the prefilled sample run (3 pages) costs 3 x USD 0.0003 + USD 0.00005 = USD 0.00095. A 100-page report with text on every page costs USD 0.03 plus the start event. 1,000 pages cost USD 0.30. If 20 of those 1,000 pages are scans, 980 pages are charged: USD 0.294. The Store page always shows the price that applies to your run.

### FAQ

**Does it read scanned PDFs?** No. There is no OCR. A PDF without a text layer is reported with status `no_text_layer`; a file with some scanned pages gives text for the other pages and lists the pages without text.

**A line I need was removed. What now?** Look at `removedLines`: it names the page, the band (header or footer), the text and the rule. Set `stripRepeatedLines` to false to keep every line, or raise `minRepeatPercent` so that only lines on more pages count as repeated.

**A running head was not removed. Why?** The rules need a head to stand apart from the text and to repeat, or to carry a page number that follows the page order. The cases that are not found are listed under Limits.

**What does it cost?** USD 0.30 per 1,000 pages with a text layer, plus Apify's start event of USD 0.00005 per run. Scans, failed and protected PDFs are free (see Pricing).

**Do I get tables?** Table rows come out as lines of text in reading order, not as cells.

**How long does it take, and how much memory?** Measured on the Apify platform on 2026-11-18: about 2.8 pages per second at 1024 MB (486 pages read in 174 seconds) and about 10.8 pages per second at 4096 MB (45 seconds); the highest memory use seen in any run was 104 MB. The sample run takes about 3 seconds. Each PDF has its own time limit (`timeoutSecPerPdf`, default 300 seconds); what was read before the limit is returned as `partial`.

**Which URLs are requested?** Only the ones you list and their redirects, after a check of the address and of the site's robots.txt; a URL that robots.txt does not allow, or whose robots.txt cannot be read, is skipped and reported with the reason.

**Can I call it from code or from an AI agent?** Yes: through the Apify API and its clients, recurring runs, webhooks and integrations, and through Apify's MCP server; the input and output are plain JSON.

### Related Actors

- **Dataset Merge & Deduplicate**: merge the page rows of several runs into one dataset and remove duplicates.

### Accuracy, measured on real PDFs

Short version: on 8 public PDFs (284 pages) that the rules had never seen, measured after the last rule change, 99.6 % of the removed words were page furniture (precision 0.9961), 95.5 % of the furniture words were removed (recall 0.9550) and 99.6 % of the body words were kept (body recall 0.9963; body precision 0.9952). An earlier version of the rules found only 58.8 % of the furniture on a first set of unseen files; that measurement and what was changed after it are shown below, so you can judge how far the numbers carry to your documents.

How it is measured: for each file the header, footer and page-number lines were written down by hand (position band, text pattern, pages) before the cleaner was run on it. The reference reading is a plain pdfplumber word list grouped into lines; words are compared per page as runs of letters or digits.

- furniture precision = removed words that are furniture / all removed words; furniture recall = removed furniture words / all furniture words;
- body recall = body words found in the page's text / all body words; body precision = output words that are body words / all output words.

#### Held-out set, first measurement before any rule was changed for these files

8 public PDFs, 1,035 pages, chosen and measured by an independent check (18.11.2026) on files the rules had never seen: a book with chapter titles in its running heads, a two-column conference paper, a statute whose heads change per section, lecture slides, a court opinion with wide margins and heads that change per part, a court form, an energy report with many tables, and a German law. This is the number to expect on documents unlike the development files.

| Document | Pages | Furniture precision | Furniture recall | Body recall | Body precision |
|---|---|---|---|---|---|
| Think Python 2e (book) | 244 | 1.0000 | 0.7126 | 0.9998 | 0.9957 |
| PMLR radford21a (two columns) | 16 | 1.0000 | 1.0000 | 0.9871 | 0.9950 |
| Title 17 circular (statute) | 486 | 0.9827 | 0.5167 | 0.9997 | 0.9848 |
| CS231n lecture 2 (slides) | 61 | 1.0000 | 0.9836 | 0.9989 | 0.9905 |
| Supreme Court slip opinion | 114 | n/a (nothing removed) | 0.0000 | 0.9974 | 0.9653 |
| Form AO 239 | 5 | 1.0000 | 1.0000 | 1.0000 | 1.0000 |
| EIA Short-Term Energy Outlook | 58 | 1.0000 | 0.8333 | 0.9525 | 0.9168 |
| Grundgesetz (German) | 51 | 1.0000 | 1.0000 | 1.0000 | 1.0000 |
| **Total (8 PDFs)** | **1,035** | **0.9913** | **0.5880** | **0.9938** | **0.9785** |

#### Fresh set, measured after the rules were changed (the independent number for the current rules)

8 more public PDFs, 284 pages, collected by the independent check before the rules were changed and kept away from whoever changed them; their header and footer lines were written down before the changed cleaner was run on them (18.11.2026). No rule was changed afterwards.

| Document | Pages | Furniture precision | Furniture recall | Body recall | Body precision |
|---|---|---|---|---|---|
| NIST SP 800-207 (technical report) | 59 | 1.0000 | 1.0000 | 1.0000 | 1.0000 |
| Nature article (two columns) | 12 | 1.0000 | 0.9649 | 0.9781 | 0.9910 |
| European Convention on Human Rights (booklet, two printed pages per PDF page) | 34 | 1.0000 | 0.0169 | 0.9952 | 0.9859 |
| CS224n lecture 1 (slides) | 40 | 1.0000 | 1.0000 | 1.0000 | 1.0000 |
| Federal Reserve Monetary Policy Report, July 2024 | 79 | 0.9880 | 1.0000 | 0.9953 | 0.9911 |
| OPM Standard Form 85 (no running heads at all) | 18 | n/a (nothing removed, which is right) | n/a (none in the file) | 1.0000 | 1.0000 |
| World Bank Pink Sheet (price tables) | 3 | 1.0000 | 1.0000 | 1.0000 | 1.0000 |
| Constitución Española, consolidated (Spanish) | 39 | 1.0000 | 1.0000 | 1.0000 | 1.0000 |
| **Total (8 PDFs)** | **284** | **0.9961** | **0.9550** | **0.9963** | **0.9952** |

Missed here: the pairs of page numbers under the booklet's two printed pages per PDF page (30 lines, see Limits) and 2 footer lines of the journal article. Kept, as they should be: 14 "Artículo n." headings that sit in the top 10 % of their pages, the column headers repeated on both table pages, and every slide title. The one removal counted as wrong in the Federal Reserve report is a running head that the hand-written pattern did not cover on one page.

#### The same 8 files after fix round 1: after the rules were changed with these files in view, so no longer an independent test

The check found running heads below the top 10 % of the page, heads that change per section, one-page section heads and small capitals split into pieces; the rules in "How the text is cleaned" were changed for these cases (general rules, no rule names a file). Measured on the same files afterwards:

| Document | Pages | Furniture precision | Furniture recall | Body recall | Body precision |
|---|---|---|---|---|---|
| Think Python 2e (book) | 244 | 1.0000 | 0.9862 | 0.9998 | 0.9993 |
| PMLR radford21a (two columns) | 16 | 1.0000 | 1.0000 | 0.9872 | 0.9952 |
| Title 17 circular (statute) | 486 | 0.9904 | 0.9950 | 0.9998 | 0.9997 |
| CS231n lecture 2 (slides) | 61 | 1.0000 | 1.0000 | 0.9989 | 0.9977 |
| Supreme Court slip opinion | 114 | 1.0000 | 0.9918 | 0.9992 | 0.9983 |
| Form AO 239 | 5 | 1.0000 | 1.0000 | 0.9902 | 0.9951 |
| EIA Short-Term Energy Outlook | 58 | 1.0000 | 0.8333 | 0.9525 | 0.9168 |
| Grundgesetz (German) | 51 | 1.0000 | 1.0000 | 1.0000 | 1.0000 |
| **Total (8 PDFs)** | **1,035** | **0.9946** | **0.9920** | **0.9940** | **0.9897** |

Reading-order checks on the two-column paper: 8 of 8. Still missed: the date at the top of the energy report's 15 text pages (set in the body font size on part of the report only; see Limits). The statute's lowest precision is a scoring effect: four footers are printed twice over themselves and the reference reading counts each word twice. The form's lower body recall is one too: the reference reading splits the small capitals of UNITED STATES DISTRICT COURT into pieces that the cleaner now reads as whole words.

#### The 12 development files the rules were developed on

12 public PDFs (712 pages): Federal Reserve releases and its annual report, a Bank of England report, two IRS publications and three arXiv papers (two of them two-column). The rules were built and tuned on these files, so they flatter the cleaner.

| | Value |
|---|---|
| Furniture precision | 0.9941 |
| Furniture recall | 1.0000 |
| Body-text recall | 0.9983 |
| Body-text precision | 0.9993 |
| Reading-order checks (hand-picked sentence sequences across columns) | 11 of 11 |
| Words split at a line end and joined | 1,352 |

| Document | Pages | Furniture precision | Furniture recall | Body recall | Body precision |
|---|---|---|---|---|---|
| Federal Reserve G.19 release | 3 | n/a (none in the file) | n/a (none in the file) | 1.0000 | 1.0000 |
| Federal Reserve H.4.1 release | 11 | 1.0000 | 1.0000 | 1.0000 | 1.0000 |
| Federal Reserve H.8 release | 22 | 1.0000 | 1.0000 | 1.0000 | 1.0000 |
| Federal Reserve Summary of Economic Projections | 17 | 1.0000 | 1.0000 | 1.0000 | 1.0000 |
| Federal Reserve Z.1 Financial Accounts | 205 | 1.0000 | 1.0000 | 1.0000 | 1.0000 |
| Federal Reserve Annual Report 2023 | 222 | 1.0000 | 1.0000 | 0.9940 | 0.9988 |
| Bank of England Monetary Policy Report | 90 | 1.0000 | 1.0000 | 0.9999 | 1.0000 |
| IRS 1040 Tax Table instructions | 28 | 0.8308 | 1.0000 | 0.9994 | 0.9999 |
| IRS Publication 15-T | 71 | 1.0000 | 1.0000 | 1.0000 | 1.0000 |
| arXiv 1810.04805 (two columns) | 16 | n/a (none in the file) | n/a (none in the file) | 0.9963 | 0.9952 |
| arXiv 1512.03385 (two columns) | 12 | 1.0000 | 1.0000 | 0.9819 | 0.9928 |
| arXiv 1706.03762 (one column) | 15 | 1.0000 | 1.0000 | 0.9933 | 0.9866 |

What the numbers mean and do not mean: the lowest furniture precision on the development files (IRS tax table instructions) comes from the word "(Continued)" at the bottom of continued tables, which repeats on most pages and is removed although the reference counts it as body text. The lowest body recall comes from figure labels and formulas. Paragraph boundaries and Markdown headings are not part of this measure. Checked separately on two of the held-out files: in the German law 686 of 690 lines that start a numbered paragraph or an article start a paragraph in the output; in the court opinion 193 of 202 indented first lines do. Split words, hand-read on four English files: about 1 in 100 joined words is a real compound that lost its hyphen ("self-serving" at a line end comes out as "selfserving" when the document never writes it inside a line). These are 28 documents, not a guarantee for yours: check `removedLines` on your own files.

### Licences

Built on pdfplumber (MIT licence) and pdfminer.six (MIT licence). The sample PDF and the unit-test fixtures are made for this Actor with invented text.

# Actor input Schema

## `samplePdf` (type: `boolean`):

Reads the 3-page sample PDF that ships with this Actor (made by us, invented text, with a running header, a footer with page numbers, a two-column page and a word split at a line end). It needs no website. Default off; the form prefills it on. Switch it off and fill in your own PDFs.

## `pdfUrls` (type: `array`):

Public http or https URLs of PDF files, one per line. Only the URLs you list are requested (and redirects from them). Each host is resolved and checked first (addresses on private, loopback, link-local, multicast, reserved or cloud-metadata networks are refused), then the URL is checked against the site's robots.txt; a URL it does not allow is skipped with a reason and not charged. At most one request per second per host. Up to 50 PDFs per run in all (URLs, keys and the sample together), each URL at most 2,000 characters, each listed once, each file at most 50 MB. Default: none.

## `pdfKeys` (type: `array`):

Keys of PDF files stored in a key-value store (content type application/pdf), one per line, read in the store picked below (or this run's own default store). Keys of this Actor's own records (INPUT, OUTPUT, STATE, SUMMARY, text-\*) are refused. Each file at most 50 MB. Default: none.

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

Pick the key-value store in your account that holds the PDFs listed under 'PDF keys' (or pass its ID through the API). The Actor only reads this store; the text files it writes always go to this run's own store. Leave empty (default) to use this run's own store.

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

Which pages to read, for example 1-3,5,8- (pages count from 1; 8- means page 8 to the end). Empty (default) reads all pages, up to the page limit below.

## `maxPagesPerPdf` (type: `integer`):

At most this many pages of each PDF are read: 1 to 500 pages, default 500. A PDF with more selected pages is read up to the limit and its document row says pageLimitReached.

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

both (default): every row has `text` (plain text) and `markdown` (headings as #, list items as -). text: plain text only. markdown: Markdown only.

## `includePageRows` (type: `boolean`):

On (default): one dataset row per page (page number, its text, the lines removed from it) before each PDF's document row, ready to use as chunks for RAG. Off: only the document row per PDF. The charge is the same either way (per page with text).

## `stripRepeatedLines` (type: `boolean`):

On (default): running headers, footers and page numbers are removed and listed in removedLines with the reason. A line counts only when it stands apart from the page's text block (a clear gap to the text, near the top or bottom edge of the page) and repeats across pages (or alternates on odd and even pages, or repeats on a stretch of pages in the slot the heads use), or is a page number that follows the page order. A repeated line attached to the text at its normal line spacing (a table's column header, a last line 'Confidential') is kept. Off: every line is kept.

## `minRepeatPercent` (type: `integer`):

A header or footer line counts as repeated when it is on at least this share of the pages with text (or of the odd or the even pages), and on at least 3 pages; a running head that changes per chapter or part counts when it is on at least this share of the pages from its first to its last page: 30 to 100 percent, default 60. Lower finds more running heads and risks removing a real line that recurs; higher removes less.

## `joinHyphenation` (type: `boolean`):

On (default): infor- + mation becomes information; a hyphen that belongs to the word is kept: before a capital or a digit (COVID-19), when the document writes the word that way (well-known), or when the next part holds a hyphen itself (state-of-the-art). A suspended hyphen before und, oder, and, or, nor, bzw., sowie or & keeps hyphen and space (Post- und Fernmeldewesen). Off: lines are joined with the hyphen kept.

## `timeoutSecPerPdf` (type: `integer`):

Reading one PDF is stopped after this many seconds: 10 to 900 seconds, default 300. The pages read before the stop are written (status partial) and charged; nothing after them. Downloading a URL has its own limit of 60 seconds. Set the run's own timeout on Apify above what you need.

## Actor input object example

```json
{
  "samplePdf": true,
  "pdfUrls": [],
  "pdfKeys": [],
  "pages": "",
  "maxPagesPerPdf": 500,
  "outputFormat": "both",
  "includePageRows": true,
  "stripRepeatedLines": true,
  "minRepeatPercent": 60,
  "joinHyphenation": true,
  "timeoutSecPerPdf": 300
}
```

# Actor output Schema

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

Per PDF, in input order: one row per page (recordType page, optional) and then one document row (recordType document) with the whole document's text and Markdown, status and the removed lines.

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

How the run ended (complete, stoppedEarly or incomplete) with counts of PDFs by status, pages with and without a text layer, pages charged and lines removed.

# 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 = {
    "samplePdf": true
};

// Run the Actor and wait for it to finish
const run = await client.actor("bardach_technologies/pdf-to-clean-text-and-markdown").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 = { "samplePdf": True }

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

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,bardach_technologies/pdf-to-clean-text-and-markdown"
        }
    }
}
```

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/GN5P7Gto6yLJvHv4F/builds/EPNBAV52F8qqV98eM/openapi.json
