Qu

pdf.page_count

Builtin index · File I/O

result = pdf.page_count(src)

Input: src · Output: result

What it is

Counts a PDF's pages. src (string path, or Vec of bytes) is the document. Counted by walking the page tree to its leaves rather than trusting the catalog's own /Count field, which a malformed or incrementally-updated file can disagree with.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = pdf.page_count(src)
src string or Vecnot documented yet
result Num
Returns a Num.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

import pdf

i = pdf.info("paper.pdf")
print("{i.pages} pages, PDF {i.version}, produced by {i.producer}")

# Join two files, then take one page out of the result -- no disk in

# between, because every function also accepts bytes.

both = pdf.merge(["intro.pdf", "results.pdf"])
print(pdf.page_count(both))
pdf.write_pages("just_page_3.pdf", both, 3)

# A page range. `1 to 5` is already a Vec, so it just works.

pdf.write_pages("front.pdf", "paper.pdf", 1 to 5)

not run by the build — this one needs something the repository cannot supply · from file-io

import pdf

doc = pdf.merge(["intro.pdf", "results.pdf"])
doc = pdf.add_bookmark(doc, "Introduction", 1)
doc = pdf.add_bookmark(doc, "Results", 3)
rows = pdf.outlines(doc)
print(rows)  # index, level, parent_index, title, page_index


doc = pdf.add_annotation(doc, 1, type = "Text", rect = [10, 10, 200, 40], text = "draft")
doc = pdf.add_attachment(doc, "notes.txt", "notes.txt")
pdf.write_pages("with_extras.pdf", doc, 1 to pdf.page_count(doc))

not run by the build — this one needs something the repository cannot supply · from file-io