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 have downloaded it, I have no idea how to convert the notebook, with nbconvert2.py since nbconvert says that it is deprecated. nbconvert2.py says that I need a profile to convert the notebook, what is it? Does there exist a documentation about this tool?
-
1[How can I get the option 'Export Notebook to Html_toc' on the 'Export Notebook as…' menu in Jupyter Lab?](https://stackoverflow.com/questions/63123830) may be of interest to people as well. – Trenton McKinney Aug 14 '20 at 07:51
-
3411 k views and no proper solution for simple things such as page breaks - 9 years later still a nightmare! – Wolfgang Fahl Jun 12 '22 at 08:25
21 Answers
If you have LaTeX installed you can download as PDF directly from Jupyter notebook with File -> Download as -> PDF via LaTeX (.pdf). Otherwise follow these two steps.
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, macOS (
brew install wkhtmltodf
) 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

- 5,489
- 46
- 45
- 50
-
3
-
3For HTML output, you should now use `jupyter` in place of `ipython` e.g. `jupyter nbconvert --to html notebook.ipynb ` – Alex Jul 11 '18 at 19:45
-
1For this to work, [jupyter_contrib_nbextensions](https://jupyter-contrib-nbextensions.readthedocs.io/en/latest/install.html) should be installed. – CharlesG Feb 05 '20 at 13:06
-
According to the above answer you need wkhtmltopdf. To install it in ubuntu 14.04 this worked for me https://gist.github.com/brunogaspar/bd89079245923c04be6b0f92af431c10 – Pradeep Singh Feb 23 '20 at 06:38
-
4
-
-
I had a problem with PDF transparency with this solution (the background looked black). I ended up fixing it by converting .ipynb -> .tex -> .pdf instead. – Matthew D. Scholefield May 08 '20 at 06:47
-
@AndiCover I don't think printing out the website is a perfect solution, a) when I did file-> print from firefox, you just get a screenshot of what is currently visible, b) when I did file-> print from Jupyter, it seemed to work OK except I didn't get any images for some reason (which was more or less the same result as exporting to MD, unfortunately). I don't see a good WYSIWYG option. – jrh Jan 05 '21 at 16:33
-
I found no good option for this, I ended up exporting the Jupyter notebook as MD then manually screenshotting the images (unfortunately the Jupyter notebook page disables right click -> Save as for images, and I was not able to figure out where the images were stored, the Markdown source was pointing to directories that did not seem to exist). – jrh Jan 06 '21 at 14:23
Also pass the --execute
flag to generate the output cells
jupyter nbconvert --execute --to html notebook.ipynb
jupyter nbconvert --execute --to pdf notebook.ipynb
The best practice is to keep the output out of the notebook for version control, see: Using IPython notebooks under version control
But then, if you don't pass --execute
, the output won't be present in the HTML, see also: How to run an .ipynb Jupyter Notebook from terminal?
For an HTML fragment without header: How to export an IPython notebook to HTML for a blog post?
Tested in Jupyter 4.4.0.

- 347,512
- 102
- 1,199
- 985
-
-
1@HammanSamuel I never touched that, let me know if you find out/ask a separate question and link it here. – Ciro Santilli OurBigBook.com Mar 02 '21 at 21:33
-
RuntimeWarning: coroutine 'ZMQSocketChannel.get_msg' was never awaited – Wolfgang Fahl May 20 '22 at 05:46
From the docs:
If you want to provide others with a static HTML or PDF view of your notebook, use the Print button. This opens a static view of the document, which you can print to PDF using your operating system’s facilities, or save to a file with your web browser’s ‘Save’ option (note that typically, this will create both an html file and a directory called notebook_name_files next to it that contains all the necessary style information, so if you intend to share this, you must send the directory along with the main html file).

- 76,608
- 25
- 108
- 120
-
1Thank you! The HTML version is really good, and really simple to obtain. However the PDF isn't good, the graphs are cut in two pieces if they are between two pages and the long code line are cut too. – nunzio13n Apr 14 '13 at 11:39
-
@nunzio13n -- Well at least you have the html... I haven't used `nbconvrt` so I can't really help you on that. Hopefully someone who has will come along... – root Apr 14 '13 at 11:55
-
-
a) Exporting as HTML from Jupyter does not seem to save pictures, b) File -> save as form Firefox gets you a completely uninteractive page that only shows what's visible. Also the link in your post is now dead. – jrh Jan 05 '21 at 16:36
nbconvert is not yet fully replaced by nbconvert2, you can still use it if you wish, otherwise we would have removed the executable. It's just a warning that we do not bugfix nbconvert1 anymore.
The following should work :
./nbconvert.py --format=pdf yourfile.ipynb
If you are on a IPython recent enough version, do not use print view, just use the the normal print dialog. Graph beeing cut in chrome is a known issue (Chrome does not respect some print css), and works much better with firefox, not all versions still.
As for nbconvert2, it still highly dev and docs need to be written.
Nbviewer use nbconvert2 so it's pretty decent with HTML.
List of current available profiles:
$ ls -l1 profile|cut -d. -f1
base_html
blogger_html
full_html
latex_base
latex_sphinx_base
latex_sphinx_howto
latex_sphinx_manual
markdown
python
reveal
rst
Give you the existing profiles.
(You can create your own, cf future doc, ./nbconvert2.py --help-all
should give you some option you can use in your profile.)
then
$ ./nbconvert2.py [profilename] --no-stdout --write=True <yourfile.ipynb>
And it should write your (tex) files as long as extracted figures in cwd. Yes I know this is not obvious, and it will probably change hence no doc...
The reason for that is that nbconvert2 will mainly be a python library where in pseudo code you can do :
MyConverter = NBConverter(config=config)
ipynb = read(ipynb_file)
converted_files = MyConverter.convert(ipynb)
for file in converted_files :
write(file)
Entry point will come later, once the API is stabilized.
I'll just point out that @jdfreder (github profile) is working on tex/pdf/sphinx export and is the expert to generate PDF from ipynb file at the time of this writing.

- 27,170
- 6
- 80
- 74
-
Thank you, you have clarified more of my doubts. But still nbconvert2.py doesn't work, because it need even a Config file `[NbconvertApp] Config file for profile './profile/latex_base.nbcv' not found, giving up` And nbconvert doesn't give me directly a pdf file, but a latex file, and I have to process the *.tex file with pdflatex, but it is a good solution. – nunzio13n Apr 14 '13 at 13:30
-
Probably it isn't a issue of nbconvert but, it is due to my lack of knowledge about. Perhaps when the documentation comes out all will be clear, ipython with the notebook and nbconvert are a very nice work and I'm sure that will be a documentation soon. – nunzio13n Apr 14 '13 at 18:38
-
This seems to lose/not give any ipython numbering (was hoping it would convert using the ipython directive). – Andy Hayden Jan 18 '14 at 04:22
-
Is there an API version to make this happen? I see that there is `IPython.nbconvert.exporters.latex` and I wonder if there is a way to get PDF output from this without the command line tool. Also, what are the dependencies to get it to work? (pandoc, tetex, other things?) And I assume it isn't cross platform (won't work on Windows). TIA! – IanSR Jun 30 '14 at 15:48
- Save as HTML ;
- Ctrl + P ;
- Save as PDF.

- 2,917
- 23
- 46
- 68
-
2It is advisable to expand all the output cells. So the PDF will be clear. – mukundha reddy Nov 24 '20 at 06:13
Only this answer would be useful to you if you have math, scientific formulae in your document. Even if you don't have them it works fine.
GUI way
Then check your Downloads folder for the file. PS: If LaTeX had any errors while compiling the PDF, it will fail. If this happens, download the HTML file and then use Web page to PDF tool or any other similar service to convert the HTML to PDF.
Command-Line way
- Open the terminal
- Navigate to the folder containing the jupyter notebook
- type "jupyter nbconvert --to pdf your_jupyter_notebook.ipynb "
PS: If it fails, try Yogesh's answer.

- 1,447
- 5
- 18
- 25

- 685
- 6
- 30
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.

- 1,447
- 5
- 18
- 25

- 900
- 1
- 11
- 21
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 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
).
2 Save html as PDF:
- Now open that
your_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
-
Thanks for the answer. How can I specify a file path to write instead of the current working directory? – mouwsy Jan 27 '22 at 11:01
-

- 1,274
- 1
- 15
- 17
-
1For me.. this is by far the best answer. Spent ages trying to get nbconvert to work and still no luck. – daticon May 03 '22 at 11:11
The plain python version of partizanos's answer.
- open Terminal (Linux, MacOS) or get to point where you can execute python files in Windows
- Type the following code in a .py file (say tejas.py)
import os
[os.system("jupyter nbconvert --to pdf " + f) for f in os.listdir(".") if f.endswith("ipynb")]
- Navigate to the folder containing the jupyter notebooks
- Ensure that tejas.py is in the current folder. Copy it to the current folder if necessary.
- type "python tejas.py"
- Job done

- 1,697
- 15
- 31

- 685
- 6
- 30
-
1Using `--template report` as an additional option compiles also a ToC to the resulting pdf by taking the different markdown headings in the notebook. – Stefan Jun 13 '20 at 07:15
For those who can't install wkhtmltopdf in their systems, one more method other than many already mentioned in the answers to this question is to simply download the file as an HTML file from the jupyter notebook, upload that to HTML to PDF, and download the converted pdf files from there.
Here you have your IPython notebook (.ipynb) converted to both PDF (.pdf) & HTML (.html) formats.

- 1,447
- 5
- 18
- 25
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.
$ 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' <type 'unicode'> 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.

- 3,457
- 1
- 20
- 26

- 9,932
- 6
- 52
- 48
-
-
ty @moldovean for pinging me to take another look at this. More googling just revealed the issue. Argument order did not matter, I still got "No such file or directory". – AnneTheAgile Oct 30 '14 at 15:09
-
@moldovean, it turns out that certain libraries are required but not installed by ipynb. In this case I need at least pdflatex on my path. See my PR to improve the error checking, https://github.com/ipython/ipython/pull/6884 – AnneTheAgile Nov 08 '14 at 01:46
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:
- Left click in the notebook
- Click 'Save As...' in the dropdown menu
- Save accordingly
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).

- 1,327
- 2
- 14
- 29
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 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 here and then select the option HTML to PDF.
Your pdf file is now ready for download.
You now have .ipynb, .html and .pdf files

- 1,447
- 5
- 18
- 25

- 1,600
- 1
- 20
- 30
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 *
}

- 1,064
- 12
- 22
notebook-as-pdfInstall
python -m pip install notebook-as-pdf pyppeteer-install
Use it
You can also use it with nbconvert:
jupyter-nbconvert --to PDFviaHTML filename.ipynb
which will create a file called filename.pdf.
or pip install notebook-as-pdf
create pdf from notebook jupyter-nbconvert-toPDFviaHTML

- 472
- 4
- 7
-
Thank you, this worked well for me. I first tried this within a Python 3.6.8 environment but ran into some issues. I then upgraded to a Python 3.7.8 environment, based on Conda, and it worked like a Charm. – mastDrinkNimbuPani Aug 02 '20 at 19:18
-
That is because asyncio is a dependency for the package, and somewhere in the code there is an asyncio.run which is a 3.7 only method. – mastDrinkNimbuPani Aug 04 '20 at 23:42
There is a library called "notebook as PDF" pip install notebook-as-pdf
.
It converts the notebooks into pdf via HTML. once the library is installed, you can find 'PDF via HTML (.pdf)' in the 'Download as' options of the 'File' tab.
File>Download as>PDF via HTML(.pdf)
Using the Ctrl+P
option may not work properly, at times when there are many cells.
Also, the paging won't be proper as well. Making it much harder for the reader to read & understand.
I found this method very intuitive, fast and better compared with other options presented here.

- 123
- 2
- 7
There are 4 ways to export Jupyter Notebook to PDF format that I am aware of and described below.
1. Print to PDF
Please open the notebook that you would like to export in Jupyter Notebook app, and select print from your web browser options. There should be an option Save as PDF
. It is the simplest approach.
2. Export to PDF with Jupyter
There is an option to export PDF directly in the Jupyter Notebook. Click File
-> Download as
-> PDF via LaTeX
or PDF via HTML
. This solution is using nbconvert
tool under the hood. You need to have installed additional packages to make it works, otherwise you will get 500: Internal Server Error
. Please check the nbconvert
installation documentation for details.
3. nbconvert
The solution is similar to point 2 but is using the command-line tool nbconvert
. Assuming that all additional packages are installed the conversion is pretty simple:
jupyter nbconvert --to webpdf --allow-chromium-download your-notebook-file.ipynb
The --allow-chromium-download
is only needed during the first use.
4. Export with Mercury
There is an open-source framework Mercury
for sharing notebooks. It converts notebooks to interactive documents (can hide the code). In Mercury
the user can tweak widgets values and execute the notebook with new parameters. The resulting notebook can be downloaded as PDF (or HTML) file.

- 5,023
- 1
- 30
- 34
The simplest way I think is 'Ctrl+P' > save as 'pdf'. That's it.
One of the simplest ways to convert a Jupyter notebook to PDF or HTML format as others have mentioned is with Google Colab. In order to use Google Colab you need a Google account. I also have video tutorials that illustrate how to convert notebooks to PDF or HTML on YouTube.
Jupyter Notebook to PDF
Upload the Jupyter notebook into the
content
folder in Google Colab.Update texlive in your session using the code below.
!sudo apt-get install texlive-xetex texlive-fonts-recommended texlive-plain-generic
Run nbconvert using the code below.
!jupyter nbconvert --to pdf "/content/your_notebook_here.ipynb"
Now you can download the converted PDF to your local computer or to your Google Drive.
Jupyter Notebook to HTML
Upload the Jupyter notebook into the
content
folder in Google Colab.Run nbconvert using the code below.
!jupyter nbconvert --execute --to html "/content/your_notebook_here.ipynb"
Now you can download the converted HTML to your local computer or to your Google Drive.

- 121
- 6
-
This answer looks like it was generated by an AI (like ChatGPT), not by an actual human being. You should be aware that [posting AI-generated output is officially **BANNED** on Stack Overflow](https://meta.stackoverflow.com/q/421831). If this answer was indeed generated by an AI, then I strongly suggest you delete it before you get yourself into even bigger trouble: **WE TAKE PLAGIARISM SERIOUSLY HERE.** Please read: [Why posting GPT and ChatGPT generated answers is not currently acceptable](https://stackoverflow.com/help/gpt-policy). – tchrist Jul 07 '23 at 13:05
-
This answer has a high probability of being AI content. Please read Stack Overflow's guide on AI content: https://stackoverflow.com/help/gpt-policy – Jul 09 '23 at 17:07
-
Definitely not ChatGPT, made a tutorial on this before ChatGPT was even publicly available. – Adrian Dolinay Jul 09 '23 at 20:39