I have a Jupyter notebook that contains markdown, code, and outputs (graphs). I would like to generate PDF from this notebook.

I tried to hide code using HTML code which I get from here then I tried to download it as pdf but again code shows up. But when I download it as HTML it don't show any code but again when I tried to convert HTML to pdf it again shows code.


Try this:

jupyter nbconvert --to pdf --TemplateExporter.exclude_input=True  my_notebook.ipynb

This also works for html output. You will find the documentation for this and other options here.

FYI, for complex notebooks, this may generate errors depending on your version of nbconvert, LaTeX and other components. In that case try to convert to html then print to pdf using a browser.

  • $\begingroup$ It is good solution. but this approch break markdown like heading shows up as # heading etc. each markdown line contains some unwanted section number like 0.0.2. $\endgroup$ Jul 8 '20 at 18:04

Make sure you are working with Qt Console (anaconda):

Install Jupiter extensions:

!pip install jupyter_contrib_nbextensions

!jupyter contrib nbextension install --user 

Enable nbextension:

!jupyter nbextension enable codefolding/main

Install pyppeteer:

!python -m pip install -U notebook-as-pdf


MAKE SURE YOUR WORKING DIRECTORY IS WHERE YOUR Untitled.ipynb FILE IS SAVED Save file to HTML format without codes:

!jupyter nbconvert Untitled.ipynb --no-input --no-prompt --to html


!jupyter-nbconvert Untitled.ipynb --no-input --no-prompt --to pdfviahtml

PS. Exporting HTML and PDF format are mutually exclusive commands, you can use either.


Make your program generate markdown output (you can save images and add references to them) and convert it using pandoc. Or don't convert, upload directly to Gitlab or Github and view.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.