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 four simple steps.

Published on Feb. 14, 2024
The planet Jupiter.
Image: Shutterstock / Built In
Brand Studio Logo

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.

How Do You Convert Jupyter Notebook to PDF?

  1. Install the necessary package.
  2. Run this code: pip install -U notebook-as-pdf.
  3. Run this code: pyppeteer-install.
  4. 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 NotebookWhat’s So Great About Jupyter Notebook?

 

4 Steps to Convert Your Jupyter Notebook to PDF

First, install the necessary package. For this example, I’m installing the package notebook-as-pdf. Next, run the following code in your command prompt.

pip install -U notebook-as-pdf

You’ll also need a setup for Chromium to perform the HTML to PDF conversion. Then run this code in your code prompt.

pyppeteer-install

Now, open the 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
Get started with Jupyter Notebooks in less than 4 minutes. | Visual Studio Code

Just like that, your notebook is a PDF file. And 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.

Explore Job Matches.