I'm trying to export my IPython notebook to pdf, but somehow I can't figure out how to do that. I searched through stackoverflow and already read about nbconvert, but where do I type that command? In the notebook? In the cmd prompt? If someone can tell me, step by step, what to do? I'm using Python 3.3 and IPython 1.1.0. Thank you in advance :)
-
http://ipython.org/ipython-doc/rel-1.0.0/interactive/nbconvert.html – joaquin Feb 13 '14 at 13:28
-
possible duplicate of [Convert ipython notebooks to pdf-html](http://stackoverflow.com/questions/15998491/convert-ipython-notebooks-to-pdf-html) – joaquin Feb 13 '14 at 13:34
-
The command should be run on the command prompt, on the same directory where you have your notebook. Executing commands on the prompt (be it windows or unix) is a complex topic, so you should familiarize yourself with it firstly, if you haven't done so already. [Here's a good reference applicable to most unix systems](https://help.ubuntu.com/community/CommandlineHowto) – loopbackbee Feb 13 '14 at 13:36
-
@goncalopp Thank you for your answer and the reference. So I guess I have to do a bunch of stuff before I'm able to execute nbconvert command in command prompt? Because when I navigate to my notebook directory and type $ ipython nbconvert etc., it says "'$' is not recognized as an internal or external command etc. – uberswag Feb 13 '14 at 13:45
-
@uberswag Do not type the `$`. It's merely used as a placeholder through documentation to indicate the command **prompt**. If you're on a unix system, you should already have it in your prompt before you begin typing. If you're on windows, you should follow a windows reference (that one is for unix/linux/ubuntu) – loopbackbee Feb 13 '14 at 13:46
-
@goncalopp Even if I don't type the '$' symbol, it still says the same thing for the first word in line (in this case, 'python'). Btw. I'm on windows. – uberswag Feb 13 '14 at 13:50
-
@uberswag Using python in the windows command prompt is not as straightforward as it is on unix. You should read [this page](http://docs.python.org/2/faq/windows.html#id2) first of all, then [this one](http://docs.python.org/2/using/windows.html#setting-envvars) – loopbackbee Feb 13 '14 at 13:54
-
@goncalopp oh well, so basically I have to do the same thing I did for python 3.3 (modify the PATH). Thank you, I'll try to figure out how to do that for IPython :) – uberswag Feb 13 '14 at 13:57
-
@goncalopp ok now I'm really out of luck. I know what to do, but the command promt still won't invoke ipython, even though ipython folder path is copied in my system path (semicolon added in front of it). Oh the horror – uberswag Feb 13 '14 at 15:08
-
I believe you have to add the `IPython/bin` directory to the `PATH`, not the `IPython` directory alone. In fact it would be easier to properly install ipython (go *inside* the `IPython` directory. Then launch `python setup.py install` You may need to launch this using an Administrator prompt). – Bakuriu Feb 13 '14 at 16:37
6 Answers
For HTML output, you should now use Jupyter in place of IPython and select File -> Download as -> HTML (.html) or run the following command:
jupyter nbconvert --to html notebook.ipynb
This will convert the Jupyter document file notebook.ipynb into the html output format.
Google Colaboratory is Google's free Jupyter notebook environment that requires no setup and runs entirely in the cloud. If you are using Google Colab the commands are the same, but Google Colab only lets you download .ipynb or .py formats.
Convert the html file notebook.html into a pdf file called notebook.pdf. In Windows, Mac or Linux, install wkhtmltopdf. wkhtmltopdf is a command line utility to convert html to pdf using WebKit. You can download wkhtmltopdf from the linked webpage, or in many Linux distros it can be found in their repositories.
wkhtmltopdf notebook.html notebook.pdf
Original (now almost obsolete) revision:
Convert the IPython notebook file to html.
ipython nbconvert --to html notebook.ipynb
This will convert the IPython document file notebook.ipynb into the html output format.
Convert the html file notebook.html into a pdf file called notebook.pdf. In Windows, Mac or Linux, install wkhtmltopdf. wkhtmltopdf is a command line utility to convert html to pdf using WebKit. You can download wkhtmltopdf from the linked webpage, or in many Linux distros it can be found in their repositories.
wkhtmltopdf notebook.html notebook.pdf

- 5,489
- 46
- 45
- 50
ipython nbconvert mynotebook.ipynb --to latex --post PDF

- 3,727
- 3
- 32
- 47

- 73
- 6
-
on my system running IPython 3.1 this gives an error: `ImportError: No module named 'PDF'` – ostrokach Apr 15 '15 at 00:59
-
2that's because the nbconvert API has changed. try: ``ipython nbconvert --to pdf
– chris May 13 '15 at 11:14
I was facing the same problem. I tried to use the option select File --> Download as --> Pdf via LaTeX (.pdf) in the notebook but it did not worked for me(It is not working for me). I tried other options too still not working.
I solved it by using the following very simple steps. I hope it will help you too:
You can do it by 1st converting the notebook into HTML and then into PDF format:
Following steps I have implemented on: OS: Ubuntu, Anaconda-Jupyter notebook, Python 3
1 Save Notebook in HTML format:
Start the jupyter notebook that you want to save in HTML format. First save the notebook properly so that HTML file will have a latest saved version of your code/notebook.
Run the following command from the notebook itself:
!jupyter nbconvert --to html notebook_name.ipynb
After execution will create HTML version of your notebook and will save it in the current working directory. You will see one html file will be added into the current directory with your_notebook_name.html
name
(notebook_name.ipynb
--> notebook_name.html
).
2 Save html as PDF:
- Now open that
notebook_name.html
file (click on it). It will be opened in a new tab of your browser. - Now go to print option. From here you can save this file in pdf file format.
Note that from print option we also have the flexibility of selecting a portion of a notebook to save in pdf format.

- 1
- 1

- 2,498
- 24
- 19
If you are using sagemath cloud version, you can simply go to the left corner, select File
--> Download as
--> Pdf via LaTeX (.pdf)
Check the screenshot if you want.
If it dosn't work for any reason, you can try another way.
select File
--> Print Preview and then on the preview
right click
--> Print and then select save as pdf
.

- 2,673
- 4
- 30
- 33

- 900
- 1
- 11
- 21
Other suggested approaches:
Using the 'Print and then select save as pdf.' from your HTML file will result in loss of border edges, highlighting of syntax, trimming of plots etc.
Some other libraries have shown to be broken when it comes to using obsolete versions.
Solution: A better, hassle-free option is to use an online converter https://www.sejda.com/html-to-pdf which will convert the *.html version of your *.ipynb to *.pdf.
Steps:
- First, from your Jupyter notebook interface convert your *.ipynb to *.html using
File > Download as > HTML(.html)
- Upload the newly created *.html file to https://www.sejda.com/html-to-pdf and then select the option HTML to PDF.
- Your pdf file is now ready for download.

- 69,473
- 35
- 181
- 253

- 1,600
- 1
- 20
- 30