Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jupyter Notebook save to PDF without Code

This has been an ongoing issue for me, as I would love to use Jupyter Notebook to write my research reports, but have found it very difficult to export my Jupyter Notebooks to PDF without code and without large formatting errors.

I am able to download the notebooks as PDF, but have not found a way to hide the code, or have the PDF resemble the formatting of the notebook.

No solution I've found on SO has been sufficient for my issue, so it may be possible that this is not the intended functionality of Jupyter Notebook.

like image 343
David Yang Avatar asked Apr 10 '18 13:04

David Yang


People also ask

How do I export a Jupyter Notebook to PDF without code?

Download Jupyter Notebook as PDF The Jupyter Notebook has an option to export the notebook to many formats. It can be accessed by clicking File -> Download as -> PDF via LaTeX (or PDF via HTML - not visible in the screenshot).

How do I manually save a Jupyter Notebook?

Saving a Jupter notebook Saving your edits is simple. There is a disk icon in the upper left of the Jupyter tool bar. Click the save icon and your notebook edits are saved.

How do I export a python notebook to PDF?

Create a notebook and the click "File -> Download As". Click the new menu entry called "PDF via HTML". Your notebook will be converted to a PDF on the fly and then downloaded.


2 Answers

I followed the suggestion by 0xffff above but the PDF output did not behave as intended (code blocks were still included).

However, their suggestion inspired me to try converting to html first using the following call: jupyter nbconvert path/to/your/ipynb --to=html --TemplateExporter.exclude_input=True

This behaved as intended, and from there, it was straightforward to print the output to PDF in a browser.

Regarding the issue with the --to=pdf flag, I've opened up an issue on the Jupyter Notebook git repo: https://github.com/jupyter/notebook/issues/3804. Will report back once I get a response.

like image 55
user10023347 Avatar answered Sep 19 '22 14:09

user10023347


Have you tried this:

jupyter nbconvert path/to/your/ipynb --to=pdf --TemplateExporter.exclude_input=True

For more on the flags, you can refer to nbconvert config options

I have successfully converted .ipynb to .html exclude the code blocks

like image 37
0xffff Avatar answered Sep 21 '22 14:09

0xffff