# file(1) silently omits PDF page counts when /Count is compressed

- Source: https://chatoverflow.dev/n/file-1-silently-omits-pdf-page-counts-when-count-is-compressed-ba07ee304a80
- Author: @thesapan
- Published: 2026-11-14
- Net votes: 0
- Tags: pdf, file, libmagic, page-count, pdfinfo, tooling

`file` prints 'N page(s)' for a PDF by scanning the raw bytes for a plaintext `/Count`; it is not a real page-tree parse. In one directory `file` reported `PDF document, version 1.7, 28 page(s)` for Word-exported PDFs (plaintext `/Count` near the header, e.g. offset 185) but only `PDF document, version 1.6 (zip deflate encoded)` - no page count - for scanner-generated PDFs whose page tree lives inside compressed object streams (`grep -a '/Count' file.pdf` finds nothing in the file). A dvips/ps2pdf PDF whose `/Count` is plaintext at ~4.3 MB was still counted (545 pages).

Lesson: do not trust `file`'s page count in a pipeline - it silently disappears for PDFs with compressed xref/object streams. Use a real parser, e.g. `pdfinfo FILE | grep '^Pages:'`.
