ForHosting KIT · Documents & PDF

Count PDF pages

Get a page total and the first page's size from the page sizes your PDF reader has already found: three pages, the first one 612 × 792 points. Every page is checked first, so a broken list never passes as a count. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon

Get a reliable page total and the dimensions of the first page from metadata already produced by a PDF reader. Supply one ordered descriptor for every page, with width and height measured in PDF points. The capability validates every descriptor, counts the entries, and returns the first page's width and height with an explicit point unit. It is useful when a workflow has parsed a PDF but needs a small, predictable summary before routing, displaying, checking, or storing the document.

Prepare the page descriptors

Provide a pages array in the same order as the pages in the PDF. Every entry must be an object with width and height fields, both expressed in PDF points. A point is one seventy-second of an inch, and it is the conventional coordinate unit exposed by PDF libraries.

Decimal measurements are accepted because crop boxes and media boxes are not always whole numbers. Use the effective page size reported by your parser, keeping its treatment of rotation consistent across the entire array. The capability does not open PDF bytes, infer dimensions, or choose between competing page boxes; it summarizes the descriptors you supply.

Include every page, even when later pages differ in orientation or size, because the number of descriptors becomes the reported page count. The first array entry is treated as the first page. An empty array is rejected because neither a meaningful total nor a first-page size can be reported from it.

Read the count and first-page size

The original numeric precision is preserved: the capability does not round, resize, normalize orientation, or convert to inches or millimetres. Only the first page dimensions are returned, even if the document mixes Letter, A4, landscape, portrait, or custom sizes later in the file. All descriptors are still validated before the result is produced.

This matters because a count based on a partly malformed list could look trustworthy while hiding incomplete parser output. The operation preserves no state and always gives the same result for the same input.

Validate metadata before routing a PDF

Use the summary as a compact checkpoint between PDF parsing and a later action. A document intake service can reject files above a page limit, choose a preview layout from the first page orientation, or attach the count and dimensions to an index record. A print workflow can compare the first-page size with an expected template before sending the original file onward.

Validation is intentionally strict: pages must be a non-empty array, every entry must be an object, and every width and height must be a finite positive number. Zero, negative values, missing fields, strings, infinities, and not-a-number values are errors rather than silently corrected measurements. Requests are also bounded at one hundred thousand descriptors.

No network request, upload, PDF decoding, or persistent storage occurs.

Enforce document page limits

Count validated descriptors before accepting a PDF into a workflow with maximum or minimum page requirements.

Choose a preview orientation

Compare the first page width and height to select a portrait, landscape, or square preview container.

Store compact PDF metadata

Add the page total and first-page dimensions to a search index, asset record, or processing log.

Does this capability read the PDF file itself?

No. It accepts ordered page descriptors already produced by a PDF parser or reader.

What unit should width and height use?

Supply both measurements in PDF points. The response identifies the unit as pt.

Does it report the size of every page?

No. It validates every descriptor, reports their total count, and returns dimensions only for the first entry.

What can I do with the page count and first-page size?

Use them as a quick check before the next step: turn away documents above a page limit, choose a portrait or landscape preview from the first page, or confirm it matches the paper a print template expects.

Why was my list of pages rejected?

Every page needs a width and a height greater than zero. An empty list, a missing measurement, a zero or a negative value stops the count, so a half-broken list never produces a total that only looks right.

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/page-count

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/page-count \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"pages":[{"width":612,"height":792},{"width":612,"height":792},{"width":792,"height":612}]}'
{
  "pages": [
    {
      "width": 612,
      "height": 792
    },
    {
      "width": 612,
      "height": 792
    },
    {
      "width": 792,
      "height": 612
    }
  ]
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "pdf.page_count",
  "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_pages100000
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 count and first-page size

The response has two top-level fields. page_count is the number of validated entries in the pages array. first_page contains width and height copied from the first descriptor, plus unit set to pt so a downstream consumer does not have to guess what the numbers mean. Array order is therefore the only rule that determines which dimensions appear under first_page.

Validate metadata before routing a PDF

For interactive checks, run the operation in the browser; for automated pipelines, the API costs $0.002 per request and returns the same deterministic JSON structure.

Can pages have different sizes or orientations?

Yes. Later descriptors may differ; the array length determines the count and the first descriptor determines first_page.

What happens when the pages array is empty?

The request fails with an invalid_input error because there is no first page to describe.

Read the full KIT documentation →