Convert IPython to PDF with Full Source Code

In this article, you’ll learn how to Convert IPython to PDF using Python.

  • 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.

Prerequisites:

  1. Python Basics
  2. -U notebook-as-pdf Basics
  3. pyppeteer-install module

Install Necessary Modules:

Open your  Prompt  and type and run the following command (individually):

pip install -U notebook-as-pdf pyppeteer-install
Code language: JavaScript (javascript)

Once Installed now we can import it inside our python code.

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. If you are using Anaconda type in anaconda command prompt.
pip install -U notebook-as-pdf
Code language: JavaScript (javascript)
  • 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. If you are using Anaconda type in anaconda command 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 (.pdf) to transform the notebook.

(or)

  • (optional) 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
Code language: CSS (css)

The result would be called example.pdf as our Jupyter Notebook is called example.ipynb.

Leave a Comment