This website uses its own and third party cookies to collect information that helps to optimize your visit to their web pages. Cookies will not be used to collect personal information. You can either allow or reject their use. You can also change their settings at any time. You will find more information on our Cookie Policy page.


DS4N6 Knowledge >> Tips & Tricks >> Converting a jupyter notebook to pdf

Converting a jupyter notebook to pdf

    jupyter nbconvert my_notebook.ipynb --to pdf

If you want to change the font size, for instance, you can do it through overriding templates (docs,base templates), but it can get complex. So the easiest way is to convert to LaTeX first, do some simple replacements, and then convert the resulting LaTeX to pdf via the pdflatex utility:

    $ jupyter nbconvert --to latex my_notebook.ipynb
    $ sed -r -i 's/documentclass\[11pt\]\{article\}/documentclass[8pt]{extarticle}/' my_notebook.tex                                                       # <---- This modifies the font size from 11pt to 8pt
    $ sed -r -i 's/geometry\{verbose,tmargin=1in,bmargin=1in,lmargin=1in,rmargin=1in}/geometry{verbose,tmargin=0.5in,bmargin=0.5in,lmargin=0.2in,rmargin=0.2in}/' my_notebook.tex # <---- This sets the margins
    $ pdflatex my_notebook
    $ rm my_notebook.tex; rm my_notebook.out; rm my_notebook.aux; rm my_notebook.log