How to Convert Jupyter Notebook to PDF

Converting your Jupyter Notebook to PDF is a useful way to share your processed data set. Here’s how to do it in three simple steps.

The planet Jupiter.
Image: Shutterstock / Built In
Brand Studio Logo
UPDATED BY
Brennan Whitfield | Dec 17, 2024

While working on my Jupyter Notebook, I sometimes want to share my processed data set — complete with the plot and markdown explanation I created — in a readable format. Luckily, there’s an easy way to convert Jupyter Notebooks into PDF files. As an example, I’ll convert the notebook below to a PDF using Python and pip.

How Do You Convert a Jupyter Notebook to PDF?

  1. Install the notebook-as-pdf package by running this code: pip install -U notebook-as-pdf.
  2. Run this code: pyppeteer-install.
  3. Download the file as a PDF.

Here’s the Jupyter Notebook in its original format.

Jupyter Notebook
Screenshot by the author

And here it is as a PDF.

Jupyter Notebook as PDF
Screenshot by the author

Now, here’s how you too can convert your notebook in a few simple steps.

More on Jupyter NotebookHow to Enable Jupyter Notebook Notifications

 

Get started with Jupyter Notebooks in less than 4 minutes. | Visual Studio Code

3 Steps to Convert Your Jupyter Notebook to PDF

1. Install the notebook-as-pdf Package Using pip

First, install the necessary package. For this example, I’m installing the package notebook-as-pdf

Run the following code in your command prompt to install the package.

pip install -U notebook-as-pdf

2. Run the pyppeteer-install Code

You’ll also need a setup for Chromium to perform the HTML to PDF conversion, which can be done by using pyppeteer-install.

After installing notebook-as-pdf, run this code in your code prompt:

pyppeteer-install

3. Open the Notebook and Download as PDF via HTML

Now, open the Jupyter notebook you want to convert to a PDF. In your notebook, click the file menu bar, select “Download as,” then select “PDF via HTML.”

Image circling “Download as” and “PDF via HTML (.pdf)”
Screenshot by author

Just like that, your notebook is a PDF file. 

If you’d rather use a command prompt to convert the notebook, you can do so with the following code.

jupyter-nbconvert --to PDFviaHTML example.ipynb

Because I titled the example Jupyter Notebook example.ipynb, the result is titled example.pdf

This is everything you need to know to convert your Jupyter Notebook into a PDF file. It’s simple, but it’ll prove useful in the long run.

Frequently Asked Questions

To convert a Jupyter notebook to a PDF:

  1. Install the notebook-as-pdf package by running pip install -U notebook-as-pdf in command prompt
  2. Run the pyppeteer-install command (downloads Chromium and is used to convert the notebook to a PDF)
  3. Open the Jupyter notebook and click “File” > “Download as” > “PDF via HTML”

To export a Jupyter notebook as a PDF, install the notebook-as-pdf package and run the pyppeteer-install command. Then, open the Jupyter notebook and click “File” > “Download as” > “PDF via HTML” to export it as a PDF.

If you can’t convert Jupyter notebook to PDF using the notebook-as-pdf package, ensure the package is properly installed and the pyppeteer-install command was properly run (this command downloads and sets up Chromium, which is needed to convert the notebook HTML to PDF format). If using Linux, make sure the necessary APT (advanced package tool) packages are also installed.

Explore Job Matches.