Easily transform your Jupyter Notebook to PDF file
While working on our Jupyter Notebook, sometimes we want to share our processed dataset complete with the created plot and the markdown explanation we already created in a readable form. There is an easy way to turn our Jupyer Notebooks into PDF files. Just with a simple setup, you can access your notebook as a PDF.
For example, I would use the notebook I provide in my article here to convert to the PDF form. Below is my Jupyter Notebook.
And below is the notebook in the PDF form.
As you can see, it shows all the codes and your explanation just like that. How fancy is it?
Now let me show you how to do it.
Jupyter-to-PDF
The first thing we need to do is to install the necessary package. Here we would use the package called notebook-as-pdf to help us convert Jupyter Notebook as PDF file. You need to run the following code in your command prompt.
pip install -U notebook-as-pdf
We also need an additional setup for Chromium. It is used to perform the HTML to PDF conversion. Just run the following code in your code prompt.
pyppeteer-install
Just like that, we have already finished our preparation. Now, let’s open the notebook you intend to convert into the PDF. In your notebook, click the file menu bar then select Download as then select the PDF via HTML to transform the notebook.
Just like that, you already have your notebook as a PDF file. If you prefer to use command prompt to convert the notebook, you could do it with the following code.
jupyter-nbconvert --to PDFviaHTML example.ipynb
The result would be called example.pdf as our Jupyter Notebook is called example.ipynb.
Conclusion
Here I showed you a trick to convert your Jupyter Notebook into a PDF file. It might be simple, but will prove useful in the long run.
If you want to read more about the package, you can visit the website here.