Extract PDF text from a page range
Extract PDF text from a page range when you already have one text block for every page and only need a specific section.
Run — free
Provide the ordered page blocks, the first page, and the last page. The capability validates the one-based range against the complete page count, selects both endpoints, and joins the chosen text in order with a visible page-break marker. It is useful for reports, contracts, manuals, and other long documents where downstream work should receive a focused excerpt instead of every page.
Provide ordered page text and an inclusive range
Start with the text that a PDF text extractor or OCR process produced for each page. Put those page objects in the same order as the original document, including pages whose extracted text is an empty string. Then set start_page and end_page using the page numbers a reader sees conceptually: page one is represented by the first array item. Both endpoints are included. A range from 3 through 5 therefore returns the third, fourth, and fifth text blocks, in that order. Keeping empty page blocks matters because removing one would shift every later page number and make the requested range refer to the wrong material. Each page must be an object with a text string; numbers, missing values, and unrelated structures are rejected instead of being silently converted. The input can contain up to ten thousand page blocks, which accommodates long reports and books while keeping execution bounded. The capability does not open or decode a PDF file itself. It operates on per-page text that another extraction step has already made available, making the selection stage explicit and predictable.
Understand validation and page boundaries
Page ranges are one-based, inclusive, and strictly validated. The starting and ending values must be integers of at least one, and the starting page cannot come after the ending page. Most importantly, neither endpoint may exceed the number of supplied page blocks. If a three-page document receives a range ending at page four, the request returns an invalid-input error rather than a partial result. This fail-fast behavior is useful in automated pipelines because it exposes a mismatch between document metadata, user selection, and extraction output. It prevents an apparently successful response from hiding missing pages. Selected page strings are concatenated with a stable marker surrounded by blank lines. The marker preserves the point at which one page ends and another begins without rewriting, trimming, or interpreting the page text. A one-page range contains no marker because there is no boundary to represent. The output also reports the selected page count and echoes the accepted start and end pages, so callers can log precisely which portion was processed. No network call, random value, clock, language model, or content inference affects the result. Identical input always produces identical output.
Use the result in focused document workflows
Selective extraction is most valuable between a page-aware extraction stage and a downstream consumer that should not receive an entire document. A contract workflow can isolate the schedule pages selected by an operator before sending them to a clause parser. A financial pipeline can retain only the management discussion section of a quarterly report for comparison. A support system can retrieve a chapter from a long product manual and index that smaller excerpt. Because the capability expects text rather than a binary PDF, it composes naturally with OCR for scanned files and with ordinary PDF text extraction for digital files. Preserve the original page array until the range has been validated; deriving the page count from the same array removes ambiguity about the allowed upper bound. Store the returned start and end values alongside the result when auditability matters. The visible page-break marker can be retained for citations or split later if a consumer needs individual boundaries. This tool intentionally does not summarize, correct, classify, or normalize the selected content. Those transformations belong in separate steps, while this operation remains a small deterministic primitive for accurate routing and reproducible document automation.
What you can do with it
Isolate a report section
Select the exact pages containing management commentary before passing the text into an analysis or comparison step.
Route contract schedules
Extract only the inclusive page range containing an appendix or schedule while preserving page boundaries for review.
Index a manual chapter
Choose one chapter from per-page manual text and send the focused result to search indexing or support tooling.
FAQ
Are start and end pages included?
Yes. The range is inclusive, so pages 2 through 4 return three page text blocks.
What happens when the range exceeds the document?
The request returns an invalid-input error when either endpoint is greater than the supplied page count.
Does this capability read a PDF file?
No. It accepts ordered per-page text that has already been extracted from a PDF.
How are selected pages separated?
Adjacent page strings are joined with a stable PAGE BREAK marker surrounded by blank lines.
What does one request cost?
The API price is $0.002 per request. The deterministic browser execution is available free on the capability page.
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/pdf/text-extract-by-page-range \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"pages":[{"text":"Cover page"},{"text":"Executive summary\nRevenue increased."},{"text":"Risk analysis\nSupply remains constrained."},{"text":"Appendix"}],"start_page":2,"end_page":3}'const res = await fetch("https://api.kit.forhosting.com/pdf/text-extract-by-page-range", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"pages": [
{
"text": "Cover page"
},
{
"text": "Executive summary\nRevenue increased."
},
{
"text": "Risk analysis\nSupply remains constrained."
},
{
"text": "Appendix"
}
],
"start_page": 2,
"end_page": 3
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/pdf/text-extract-by-page-range",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"pages": [
{
"text": "Cover page"
},
{
"text": "Executive summary\nRevenue increased."
},
{
"text": "Risk analysis\nSupply remains constrained."
},
{
"text": "Appendix"
}
],
"start_page": 2,
"end_page": 3
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/pdf/text-extract-by-page-range", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"pages":[{"text":"Cover page"},{"text":"Executive summary\\nRevenue increased."},{"text":"Risk analysis\\nSupply remains constrained."},{"text":"Appendix"}],"start_page":2,"end_page":3}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"pages":[{"text":"Cover page"},{"text":"Executive summary\nRevenue increased."},{"text":"Risk analysis\nSupply remains constrained."},{"text":"Appendix"}],"start_page":2,"end_page":3}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/pdf/text-extract-by-page-range", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"pages": [
{
"text": "Cover page"
},
{
"text": "Executive summary\nRevenue increased."
},
{
"text": "Risk analysis\nSupply remains constrained."
},
{
"text": "Appendix"
}
],
"start_page": 2,
"end_page": 3
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "pdf.text_extract_by_page_range",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Limits
max_mb | 25 |
max_pages | 200 |
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |