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.
Written by Cornellius Yudha Wijaya Published on Feb. 14, 2024 Image: Shutterstock / Built InWhile 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.
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.
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.”
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.