ForHosting KIT · Documents & PDF

Parse a PDF page range string into page numbers

Turn a page selection such as 1-3,5,8-10 into the exact list of pages an export process needs.

● BetaFree · in your browser
Use it from WebAPIEmailTelegramApp soon

This parser expands inclusive ranges, keeps the order in which pages were first requested, removes duplicates, and checks every result against the document's total page count. It gives applications a predictable validation step before they extract, print, split, or export a PDF, without silently accepting pages that do not exist or rearranging the user's intended sequence.

Write a clear page range expression

Enter individual page numbers, inclusive page ranges, or a comma-separated mixture of both. For example, 1-3,5,8-10 represents pages 1, 2, 3, 5, 8, 9, and 10. Spaces around commas and hyphens are accepted, so text copied from a form can remain readable. Page numbering starts at 1, matching the labels people see in ordinary PDF readers. Every item must be a positive integer or an ascending range whose first page is no greater than its last page. Empty items, decimal values, words, negative numbers, and descending expressions are rejected instead of being guessed. This strict grammar is useful at an application boundary because a malformed request cannot quietly turn into the wrong export. Supply the document's total page count separately. The parser uses that value as a hard upper bound, ensuring the selection describes real pages in the specific document rather than merely looking syntactically valid.

Understand ordering and duplicate removal

The result follows the order in which each page first appears in the expression. A range expands from its start to its end, and later items continue from there. If a page occurs again, whether through an overlapping range or an explicit number, the duplicate is omitted while the first occurrence stays in place. For example, 3-5,1,4,2 produces 3, 4, 5, 1, 2. This behavior matters when the list feeds a PDF export or reordering operation: sorting the pages numerically would erase the user's requested sequence, while retaining duplicates could export the same page more than once. The response includes both the expanded pages array and its count, making it easy to pass the array to another operation and show a selection summary without recounting it. Expansion is deterministic, with no network calls, document upload, random values, or environment-dependent behavior, so identical inputs always return identical JSON.

Validate before exporting or printing

Use this parser immediately after reading a range from a user and before starting a more expensive PDF task. First obtain the PDF's total page count from trusted document metadata, then submit that count with the range string. If any single page or range endpoint exceeds the total, the entire request fails with an invalid-input error that identifies the offending page. Nothing is clipped to the last page, because silent clipping can hide typing mistakes and produce incomplete records. The same fail-fast rule applies to zero, unsafe integers, malformed separators, and reversed ranges. A successful result is therefore safe to treat as an explicit selection within the declared document bounds. The capability parses selection text only: it does not open, inspect, modify, or store the PDF itself. That separation keeps the validation fast and lets the resulting list work with different downstream tools, including page extraction, print queues, preview generation, batch exports, and custom document workflows.

Validate an export dialog

Expand the range typed by a user and reject the request before export when it names a page outside the document.

Prepare a PDF extraction job

Convert compact selection text into the explicit page array required by a page extraction or splitting service.

Normalize saved print selections

Store one ordered, deduplicated representation even when the original expression contains overlaps or repeated pages.

What does it cost?

Each API request costs $0.002. The browser version can run locally without uploading a PDF.

Are range endpoints included?

Yes. A range such as 4-6 expands to pages 4, 5, and 6.

What happens to duplicate pages?

Duplicates are removed, and the position of each page's first appearance is preserved.

Does the result get sorted?

No. The parser preserves the user's requested order while expanding each range in ascending order.

What happens when a page exceeds the document size?

The request fails with an invalid-input error. Pages are never clipped or silently discarded.

Does this capability read or modify my PDF?

No. It receives only the range text and total page count, then returns page numbers.

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.

POSThttps://api.kit.forhosting.com/pdf/export-range-string-parse

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.

curl -X POST https://api.kit.forhosting.com/pdf/export-range-string-parse \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"range_string":"1-3,5,8-10","total_pages":10}'
{
  "range_string": "1-3,5,8-10",
  "total_pages": 10
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "pdf.export_range_string_parse",
  "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.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

max_chars10000
max_items100000
HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Read the full KIT documentation →