nbconvert is a free command line tool to convert Jupyter Notebook to HTML, Markdown, PDF in Windows. You can also use it on other platforms as well with ease. And not just the aforementioned formats but you can use it to convert a Jupyter notebook to other formats as well such as ASCII, Latex, HTML Slideshow, reStructuredText, and executable script. There is a single command to convert a notebook and it saves the generated file in the same directory. You can feed it a single IPYNB file or multiple files and it can convert them all in a few seconds.
If you use Jupyter Notebook for keeping Python code or for sharing it then you will like this post. Sharing code via Jupyter Notebook is fine but to open that notebook, the other person needs to have Jupyter installed. But if you want to send the notebook to a naive person who doesn’t have much idea about Jupyter Notebooks then you will have to convert it first. And there are very limited number of tools out there to do it. And one such tool is nbconvert and I will talk about it here in this post.
How to Convert Jupyter Notebook to HTML, PDF, Markdown?
Using nbconvert to convert a Jupyter Notebook to other formats is very simple. It is written in Python which is why you can easily setup it on almost any platform and convert ipynb files. Also, apart from as a command line tool, you can use nbconvert as a library too. If you want to create some program or application which requires ipynb conversion then you can do that.
Currently, you can convert a Jupyter Notebook to HTML without any dependency. But to convert to other formats, you will need some external tools. For markdown, latex and PDF conversion, you will have to install Pandoc and Latex on your PC. After installing these two, you can proceed with the installation tool. To install nbconvert, run the following command in terminal or command prompt.
pip install nbconvert
Change the current directory to where the sample or input Jupyter Notebook is. Run the following command to convert the given notebook to HTML. The default conversion parameter is HTML. So, even if you don’t specify the “–to” parameter, it will convert the input notebook to HTML.
jupyter nbconvert --to HTML sample.ipynb
To convert a ipynb file to markdown, you use the following syntax of the command.
jupyter nbconvert --to MARKDOWN sample.ipynb
For converting the desired Jupyter Notebook to PDF, you execute the following command. For this conversion, Latex is necessary. As it first converts the input file to an intermediary Tex file and then create PDF from it. It creates a high quality PDF from the Jupyter Notebook.
jupyter nbconvert --to PDF sample.ipynb
Above, you can see how this Jupyter Notebook Converter tool works. You can use it with the similar syntax and convert any Jupyter Notebook to other format that it supports. Or, you can use it as a library in your own applications. You can read the whole documentation about this tool here.
This is all about this handy Jupyter Notebook converter that you can use easily on whatever platform you are one. Convert any notebook to PDF, HTML, and other formats it supports. Also, not only one but you can convert multiple notebooks with this too. So, if you are looking for a simple tool to convert Jupyter Notebooks then this post will be quite helpful.