# A Beginner’s Guide to Opening PDFs with PyMuPDF

The code below opens an existing PDF so you can read, extract, or modify its contents.

## 1\. Import PyMuPDF

```python
import pymupdf
```

This imports the PyMuPDF library and makes its PDF tools available in your Python program.

## 2\. Open the PDF

`pymupdf.open()` opens the PDF file named `data.pdf`. The returned document is stored in the variable `doc`, which you can then use to access the PDF's pages and content.

```python
doc = pymupdf.open("data.pdf")
```

## Complete Example

```python
%pip install -q -U pymupdf

from google.colab import files
uploaded = files.upload()

import pymupdf
doc = pymupdf.open("data.pdf")
```

In short: `import pymupdf` loads the library, while`pymupdf.open("data.pdf")` opens the PDF and stores it in `doc` for further processing.

***Note:*** *Make sure the* `pymupdf` *package is installed and the PDF file (*`data.pdf`*) is uploaded to your Google Colab environment before running the following code.*

### **\-Want to learn how to install the** `pymupdf` **package in Google Colab?**

Check out this mini-guide: [<u>How to Install PyMuPDF in Google Colab</u>](https://payhip.com/PDFPythonHub/blog/news/how-to-install-pymupdf-in-google-colab).

### **\-Want to learn how to upload your PDF file in Google Colab?**

Check out this mini-guide: [<u>Uploading Files in Google Colab</u>](https://payhip.com/PDFPythonHub/blog/news/uploading-files-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](https://colab.research.google.com/drive/1zlZaeJzMq7iXaaRAXeiQ4KhwTniGyEX4?usp=sharing)\]

---

This mini-guide was originally published on [PDF Python Hub](https://payhip.com/PDFPythonHub), where you can find more in-depth Python resources for working with PDFs.
