I want to convert my ipython-notebooks to print them, or simply send them in html format. I have noticed that there exists a tool to do that already, nbconvert. Although I h
I can't get pdf to work yet. The docs imply I should be able to get it to work with latex, so maybe my latex is not working. http://ipython.org/ipython-doc/rel-1.0.0/interactive/nbconvert.html
$ ipython --version
1.1.0
$ ipython nbconvert --to latex --post PDF myfile.ipynb
[NbConvertApp] ...
raise child_exception
OSError: [Errno 2] No such file or directory
$ ipython nbconvert --to pdf myfile.ipynb
[NbConvertApp] CRITICAL | Bad config encountered during initialization:
[NbConvertApp] CRITICAL | The 'export_format' trait of a NbConvertApp instance must be any of ['custom', 'html', 'latex', 'markdown', 'python', 'rst', 'slides'] or None, but a value of u'pdf' was specified.
However, HTML works great using 'slides', and it is beautiful!
$ ipython nbconvert --to slides myfile.ipynb
...
[NbConvertApp] Writing 215220 bytes to myfile.slides.html
//Update 2014-11-07Fri.: The IPython v3 syntax differs, it is simpler;
$ ipython nbconvert --to PDF myfile.ipynb
In all cases, it appears that I was missing the library 'pdflatex'. I'm investigating that.
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
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 your_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
(your_notebook_name.ipynb
--> your_notebook_name.html
).
your_notebook_name.html
file (click on it). It will be opened in a new tab of your browser.Note that from print option we also have the flexibility of selecting a portion of a notebook to save in pdf format.
I've been searching for a way to save notebooks as html, since whenever I try to download as html with my new Jupyter installation, I always get a 500 : Internal Server Error The error was: nbconvert failed: validate() got an unexpected keyword argument 'relax_add_props'
error. Oddly enough, I've found that downloading as html is as simple as:
No print preview, no print, no nbconvert. Using Jupyter Version: 1.0.0
. Just a suggestion to try (obviously not all setups are the same).
The plain python version of partizanos's answer.
import os
[os.system("jupyter nbconvert --to pdf " + f) for f in os.listdir(".") if f.endswith("ipynb")]
I combined some answers above in inline python that u can add to ~/.bashrc or ~/.zshrc to compile and convert many notebooks to a single pdf file
function convert_notebooks(){
# read anything on this folder that ends on ipynb and run pdf formatting for it
python -c 'import os; [os.system("jupyter nbconvert --to pdf " + f) for f in os.listdir (".") if f.endswith("ipynb")]'
# to convert to pdf u must have installed latex and that means u have pdfjam installed
pdfjam *
}