Home > Mobile >  How to convert Jupyter notebook to PDF?
How to convert Jupyter notebook to PDF?

Time:06-28

How to convert Jupyter notebook to pdf, only obtaining the markdown cells and output?

I am having difficulty using Jupyter nbconvert to export my Jupyter notebook to a pdf. I would like the pdf to show my markdown cells and the output of the cells but NOT the code. For the purpose of this question the name of my notebook is Deskbook.ipynb. I have been trying these commands from the same working directory of the notebook.

I have attempted this in the notebook itself, as follows:

!ipython nbconvert --to pdf --no-input Deskbook.ipynb

and the error I receive is

ipython: error: unrecognized arguments: --no-input Deskbook.ipynb

I have also tried the following on a Mac terminal

% $jupyter nbconvert --to pdf --no-input Deskbook.ipynb

and the error I receive is

zsh: command not found: nbconvert

I have also tried the same command in the the Jupyter notebook, python shell (through Terminal on Mac and AnacondaPrompt.exe on my Windows 10 Thinkpad), and receive the following error:

 $jupyter nbconvert --to pdf --no-input 'Deskbook.ipynb'
    ^
SyntaxError: invalid syntax

Ideally, I would like to add the functionality of converting to pdfs in a cell at the end of the notebook. The reason I am doing this is to share the output of my notebook (Figures and html rendered Pandas dataframes) with people who do not code. I have also tried to download using the drop down menu in Jupyter, and while PDF via latex does work, my tables are all scrambled in the file. I have seen a variety of answers about this on stack overflow, but none seem to be working for me. I have access to both a Windows 10 and Mac OS Big Sur setup

CodePudding user response:

Try looking at notebook-as-pdf.
It might be easier to convert Jupyter Notebooks to PDFs.

CodePudding user response:

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

!pyppeteer-install

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

EXPORT TO PDF FORMAT:

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

[https://datascience.stackexchange.com/questions/77352/generate-pdf-from-jupyter-notebook-without-code]

Follow the steps carefully.

  • Related