Jupyter Notebook to PDF in a few lines

towards-data-science

This post was originally published by Cornellius Yudha Wijaya at Towards Data Science

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.

Spread the word

This post was originally published by Cornellius Yudha Wijaya at Towards Data Science

Related posts