Keencrest guides

Split PDFs into chunks for RAG (Markdown, pay per PDF): $0.0035 each

By Keencrest · 2026-11-01

To put a long PDF into a vector database you cut it into pieces of a few hundred tokens and keep the page of each piece so an answer can cite it. This guide shows how to get those pieces from an API that charges per PDF, with a real run on an 85-page public document. One honest point first: the Actor returns the document as Markdown, and it can also return the cut pieces, but the cutting is by size, not by chapter.

Price

JobCost
1 PDF, any length up to the page cap (200 pages by default)$0.0035
1,000 PDFs$3.50
Dead link, not a PDF, or no text layer$0, returned with the reason

The price is per document, so the 85-page file below cost the same as a 2-page one. There is no start fee and no monthly plan.

A real run on 85 pages

On 2 November 2026 we ran it on Apify's servers on House Document 110-50, the Constitution of the United States as amended, printed by the US Government Publishing Office. It is a work of the US government, so it is in the public domain, and the host's robots.txt allows the /content/ path. The input:

{"urls": [{"url": "https://www.govinfo.gov/content/pkg/CDOC-110hdoc50/pdf/CDOC-110hdoc50.pdf"}], "outputFormat": "markdown", "chunkSize": 1000, "chunkOverlap": 100}

The run (id DyvSmjmyLHRlFTUAQ) took 3.2 seconds and charged one PDF, $0.0035. The row said pageCount: 85, 41,473 words, 240,595 characters, and a chunks array of 332 pieces of about 1,000 characters with 100 characters of overlap. Each piece has index, text, pageStart and pageEnd. Chunk 31, cited to page 11:

all be, for the Erection of Forts, Magazines, Arsenals, dock-Yards, and other needful buildings;—And 18To make all Laws which shall be necessary and proper for carrying into Execution the foregoing Powers, and all other Powers vested by this Constitution in the Government of the United States, or in any Department or O ...

Words broken across lines are joined (this chunk reads "buildings" and "carrying", and the second one used to be split by a paragraph break). Expect an occasional leftover on other typeset documents.

Use the chunks

Fetch the dataset row, then group or embed the chunks. This is the whole step:

by_page = {}
for c in chunks:                      # chunks = item["chunks"] from the dataset row
    by_page.setdefault(c["pageStart"], []).append(c)
records = [{"id": c["index"], "text": c["text"], "page": c["pageStart"]} for c in chunks]  # ready for an embedding call

We ran this exact code on the stored chunks of the run above: 332 chunks in, 332 records out, pages 1 to 85.

Why not split by headings?

If your documents have a clean outline, you can cut the markdown field at heading lines:

import re
sections = [s for s in re.split(r"(?m)^(?=#{1,3} )", item["markdown"]) if s.strip()]

On this document it works. The Markdown had 38 heading lines in 85 pages (an earlier build of the Actor returned 103 here, mostly sentence fragments from bold and small caps inside running text, and a later one found only 16 of the 34 article markers). 34 of them are the "ARTICLE" markers: the 7 original articles and all 27 amendments. The rest are the title, the ratification heading and the index. A sample:

That is a usable outline here: every one of the 27 amendments starts its own section, so a heading split gives one piece per amendment. Heading levels are inferred from fonts and layout, so the result is only as good as the file. Count the headings on a few of your own files first, and fall back to chunkSize with pageStart when the outline is incomplete.

Scanned PDFs (no text layer)

A PDF that is only pictures of pages has no text to extract. The Actor returns it with hasTextLayer: false and does not charge. For those files use OCR API, pay per page, no subscription and cut its text yourself.

Limits to know

Try it: PDF to Markdown & Text Extractor on Apify. $0.0035 per PDF; scans and failed links are free. The Apify free plan includes monthly credit, so a test run costs nothing out of pocket.

Related guides

All Keencrest guides