Exporting an IPython Notebook Dashboard to PDF

In this recipe, you'll learn how to export an IPython Notebook to a PDF file. There are two methods which you can try. If the first works for you, then great, but if it doesn't, then try Method 2.

Getting Ready…

Before attempting a conversion to PDF, add the following line to your ~/.jupyter/jupyter_nbconvert_config.py file. You may need to create this file:

c.ExecutePreprocessor.timeout = 300

This will ensure that a PDF can be generated, and it won't timeout while running the notebook, which can happen, especially if you're importing a few million rows to run through an analysis. Depending on how much data your notebook needs to import before running, you may need to increase or decrease the timeout value.

How to do it...

Method one…

  1. First, install Pandoc (http://pandoc.org/installing.html). Pandoc is a swiss-army knife for converting files from one markup format into another, and can be installed on Windows, Mac OS X, and Linux.
  2. Next, you need to install LaTeX. On the Mac, you can download MacTeX (http://tug.org/mactex/mactex-download.html). For other operating systems, visit the LaTeX website (https://latex-project.org/ftp.html), and download the software for your operating system.

Once everything is installed, change into the directory where your notebook file is and run the following command:

jupyter nbconvert --to pdf --execute 'name_of_notebook.ipynb'

This looks almost identical to the previous recipe with one exception—instead of using --to html, we are using --to pdf.

If you try this and it does not work, try Method 2.

Method 2…

If Method 1 fails due to library conflicts on your computer, you can use wkhmltopdf, another open source command-line tool, to convert your notebook to a PDF.

First, install wkhtmltopdf by visiting http://wkhtmltopdf.org/index.html and downloading the version for your operating system.

Next, convert the notebook to HTML using the command that we saw in the previous recipe:

jupyter nbconvert –to html –execute 'name_of_notebook.ipynb'

After that, use wkhtmltopdf to convert the HTML file to a PDF file:

wkhtmltopdf name_of_notebook.html name_of_notebook.pdf
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset