Count PDF Pages with Python and PyMuPDF

Once you have opened a PDF with PyMuPDF, you can easily find out how many pages it contains.
Using page_count
page_number = doc.page_count
print(page_number)
The page_count property returns the total number of pages in the PDF.
Here, the number of pages is stored in the variable page_number, and print() displays it.
For example, if the PDF contains 44 pages, the output will be:
44
Using len()
You can also use Python's built-in len() function:
len(doc)
This returns the total number of pages in the PDF as well.
For example:
print(len(doc))
Example Output:
44
Key takeaway
Both approaches give you the number of pages:
doc.page_countor
len(doc)
Complete Example
# Method 1
page_number = doc.page_count
print(page_number)
# Method 2
print(len(doc))
Open the notebook
Open the Google Colab notebook for this PDF mini-guide and run the code as you follow along.
More PDF Python Resources
Want to learn how to open a PDF file?
Check out this mini-guide:
About the author
- PDF & Python Lab is dedicated to teaching PDF programming, automation, and engineering with Python through practical, project-based courses. Whether you're a complete beginner or an experienced Python developer, the goal is to help you build the skills needed to work with PDF documents confidently—from reading and extracting data to building enterprise document processing and AI-powered workflows. What You'll Learn The curriculum covers every stage of PDF processing, including: -PDF fundamentals -Document extraction -PDF manipulation -Forms, tables, and images -OCR and scanned documents -Security and redaction -Enterprise automation -AI-powered document processing How You'll Learn Every course is designed to be: -Beginner-friendly with clear, step-by-step explanations -Focused on practical, real-world applications -Built around hands-on projects and assessments -Structured as a complete learning path from beginner to expert
Comments
Join the discussionNo comments yet. Be the first to comment.



