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?
- Install the necessary package.
- Run this code:
pip install -U notebook-as-pdf
. - Run this code:
pyppeteer-install
. - Download the file as a PDF.
Here’s the Jupyter Notebook in its original format.
And here it is as a PDF.
Now, here’s how you too can convert your notebook in a few simple steps.
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.”
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.