pagecount

pagecount

pagecount prints the page count of a PDF. If it can’t be sure of the count, it refuses with exit code 2 instead of guessing.

The three rules

  • Your documents stay with you. pagecount reads one file and sends nothing anywhere; a test checks the binary links no network packages.
  • Nothing to operate. One static binary. No server, no account.
  • Nothing is metered. Open source; never a charge per document or per month.

Does it count correctly?

We checked pagecount against a reference tool, pdfinfo from Poppler. On 200 PDFs from the RECAP court-filing corpus (1622 pages, largest file 55 pages), all 200 counts agree and none were refused. These files are ordinary well-formed PDFs; the test says nothing about damaged or hostile files. The test suite also checks 42 malformed and hostile PDFs.

When it refuses

pagecount refuses, with exit code 2, when the file gives two answers or none:

  • the file is encrypted;
  • there is no startxref, or /Root or /Pages cannot be resolved;
  • a cross-reference entry points at the wrong object number or generation;
  • the page tree has a cycle, an untyped node, a /Page that also has /Kids, or a kid that is missing or free;
  • the root /Count is missing, is not an integer, lies beyond ±2⁵³, or disagrees with the walked tree.

A page object listed twice in /Kids counts once, because it is one object. Acrobat and pdf.js render it twice.

Download

Prebuilt binaries for Linux, macOS and Windows (amd64 and arm64) are on the releases page, with a checksums.txt. They ship as .tar.gz archives (Windows: .zip).

On macOS or Linux:

tar xzf pagecount_darwin_amd64.tar.gz
xattr -d com.apple.quarantine pagecount 2>/dev/null   # macOS, browser download only
./pagecount FILE.pdf

macOS blocks an unsigned program downloaded through a browser with “Apple could not verify pagecount is free of malware”; the xattr line removes that flag.

Or build from source:

Install

go install github.com/docs2info/pagecount@latest
% pagecount three.pdf
three.pdf: 3 pages

Source

github.com/docs2info/pagecount

peter@docs2info.com