Your Cart
Loading
Mini-guide to extracting selected PDF pages with Python, PyMuPDF, and Google Colab.

How to Split a PDF by Custom Page Selections in Google Colab

With Python, PyMuPDF, and Google Colab, you can easily extract specific pages from a PDF and save them as a new PDF. This is useful when you need to extract individual chapters, sections, or selected pages.


1. Install PyMuPDF

Run this cell first:

How to Install PyMuPDF in Google Colab


2. Upload your PDF

Import Google Colab's file upload tool and select your PDF:

How to Upload PDF files in Google Colab


3. Open the PDF

Import PyMuPDF and open the uploaded file:

How to import PyMuPDF Using Python


Note: PyMuPDF uses zero-based page indexing.
Page 1 = index 0
Page 2 = index 1
Page 3 = index 2


4. Select the pages to extract

Specify the pages you want to extract.

For example, this selects pages 1, 3, and 5:

How to Select Specific Pages Using Python


5. Create a new PDF

Create a new PDF and copy the selected pages into it:

Python code using PyMuPDF to create a new PDF, copy selected pages from an existing PDF into it, save the result as selected_pages.pdf, and close both PDF documents.


6. Download the new PDF

Once the PDF has been created, download it to your computer:

How to Download a PDF File in Google Colab


Complete Example

How to Split a PDF by Custom Page Selections with Python in Google Colab



Open the notebook

Open the Google Colab notebook for this PDF mini-guide and run the code as you follow along.

[Open in Google Colab]



Ready to put this into practice? Check out the Python and PDF resources in our store.


👉 Visit the store



More PDF Python Resources

Want to learn how to Split a PDF into Separate PDF Pages in Google Colab?


Check out this mini-guide: How to Split a PDF into Separate PDF Pages in Google Colab.





Subscribe to our newsletter

Get notified when new PDF mini-guides, resources, templates, bundles, ebooks, and courses are released.