Jupyter Notebook to pdf/html file
less than 1 minute read
If you would like to create a pdf/html from your jupyter notebook, you can use the handy nbconvert
tool of jupyter
. Here is how you can use it.
Setup
- Make sure you have
jupyter
andnbconvert
installed in your activated python virtual environment. You can installnbconvert
by just this command:pip install nbconvert
Converting a notebook into PDF
jupyter nbconvert --to pdf yourNotebook.ipynb
- This generates a PDF via your system’s
latex
(or more specificallyxelatex
) command. So, make sure you have these installed in your system otherwise thenbconvert
will fail.
Converting a notebook into HTML
jupyter nbconvert --to html yourNotebook.ipynb
- This exports a html version of the jupyter notebook.
Converting a notebook into WebPDF
jupyter nbconvert --to webpdf yourNotebook.ipynb
- This generates a PDF by first rendering to HTMMLM, and rendering the HTML chromium headless, and exporting to PDF. The exporter supports the same template as
--to html
. Thewebpdf
exporter requires theplaywright
Chromium automation library, which can be installed viapip install nbconvert[webpdf]
command.