Return the PDF's numeric page count and, when a limit was supplied, an explicit pass/fail comparison. Do not edit or rebuild the document unless the user also requested that separate work.
Quick Start
-
Resolve the exact PDF path and confirm the file exists.
-
Run the bundled counter from this skill directory:
python3 scripts/count_pdf_pages.py <path-to-pdf> -
Treat exit code
0plus a single integer on stdout as success. Exit code2means none of the available backends could determine the count; report the dependency/error message instead of guessing. -
Compare the integer to the user's rule:
- maximum
N: pass whencount <= N; - minimum
N: pass whencount >= N; - exact
N: pass whencount == N.
- maximum
One successful counter result for the exact output file completes counting. Do not render pages or run additional backends unless the file changed or a concrete discrepancy calls that result into question.
Output Contract
Report the file, page count, limit if any, and result. When over or under the limit, include the exact difference. Example: 27 pages; maximum 25; fail by 2 pages. Keep any requested caveat or next action, but omit backend narration on success.
If another task changed the source document, count the rebuilt output PDF, not the stale pre-edit artifact. If no rebuilt PDF exists, state that the count is for the currently supplied file.
Gotchas
- Do not infer pages from filename, file size, source-document pagination, or a viewer thumbnail count.
- Encrypted or malformed PDFs may fail every backend. Surface the failure; do not report zero pages.
- The script tries
pypdf,pdfinfo, then macOSmdls. If no backend works, installpypdfor providepdfinforather than rewriting the script during the counting task. - A request to check a limit does not authorize layout compression or content cuts. Offer or perform PDF editing only when asked.