Your Cart
Loading
Google Colab code example using PyMuPDF to split a multi-page PDF into individual PDF files and download them as a ZIP file.

How to Split a PDF into Separate PDF Pages in Google Colab

If you have a multi-page PDF and want to turn each page into a separate PDF file, you can do this easily with PyMuPDF in Google Colab.


1. Install PyMuPDF

First, install the PyMuPDF library:

How To Install PyMuPDF Using Python in Google Colab


2. Import Libraries

Then import the libraries you’ll need:

How To Import Libraries Using Python


3. Upload Your PDF

The following code opens a file picker so you can upload your PDF:

How To Upload PDF Files in Google Colab


The uploaded file is stored in the variable input_pdf.


4. Create an Output Folder

Next, create an output folder called split_pages where the individual PDF pages will be saved:

How To Create an Output Folder in Google Colab


We set exist_ok=True so that Python won't return an error if the folder already exists.


5. Open the PDF

Next, open the uploaded PDF with PyMuPDF:

How To Open a PDF Using PyMuPDF


The variable doc now represents the entire PDF document.


6. Split the PDF into Individual Pages

The following loop goes through every page in the PDF. For each page, it creates a new PDF, copies the current page into it, saves it, and then closes the new PDF:

How To Split a PDF into Individual Pages Using Python



Here's what happens:

  • range(len(doc)) generates the page indexes for every page in the PDF.
  • i is the page index, starting at 0.
  • A new empty PDF is created for each page.
  • insert_pdf() copies the current page into the new PDF.
  • save() creates a file such as page_1.pdf, page_2.pdf, and so on.
  • close() closes the newly created PDF after it has been saved.


For example, a 5-page PDF will produce:

split_pages/

├── page_1.pdf

├── page_2.pdf

├── page_3.pdf

├── page_4.pdf

└── page_5.pdf


7. Close the Original PDF

Once all the pages have been processed, close the original PDF:

How To Close a PDF Document Using Python


8. Create a ZIP File

Instead of downloading every PDF individually, you can put all the individual PDFs into a ZIP file:

How To Create a ZIP File Using Python in Google Colab


This creates:

split_pages.zip


and automatically starts the download in Google Colab.


Complete Example

How to Split a PDF into Separate PDF Pages Using Python and PyMuPDF




Why Split a PDF into Separate PDFs?

Splitting a PDF into individual pages is useful when you need to:

  • Extract specific pages from a larger document.
  • Process pages separately.
  • Upload individual pages as separate documents.
  • Share only certain pages with someone.
  • Organize a large PDF into smaller files.




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 count the number of pages in a PDF?


Check out this mini-guide: How to Count the Number of Pages in a PDF Using PyMuPDF.




Subscribe to our newsletter

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