Best way to print Jupyter notebook slides? How to put a page break?

Lisa picture Lisa · Aug 10, 2016 · Viewed 14.7k times · Source

I want to print my jupyter notebook and share the hardcopy with non-programmer coworkers.

What I have done so far:

My question: How to put a page break to specify the contents on each pdf page?

Once I convert the slides(html) to pdf, the text and graph is not at the expected location in pdf. I want the graph and the text explaining the graph to be in the same page. Do I need to put some page breaks in markdown cell of my Jupyter notebook? Or how to specify the content on each page of pdf, instead of letting the browser decide

Also, I'm trying to convert Jupyter notebok directly to pdf, but encounters issues: Convert jupyter notebook to pdf: Error encounters when install pandoc

Answer

Roman Orac picture Roman Orac · May 19, 2020

I wrote an Ebook in Jupyter Notebooks. I put each chapter in a separate Notebook. Then I converted a Notebook to HTML with nbconvert and then use wkhtmltopdf to convert it to PDF. The final step was to merge those PDFs with cpdf. This was the only way I was able to get page breaks in PDF.

jupyter nbconvert --to html Chapter1.ipynb
jupyter nbconvert --to html Chapter2.ipynb

wkhtmltopdf --enable-internal-links -L 10mm -R 9.5mm -T 10mm -B 9.5mm Chapter1.html Chapter1.pdf

wkhtmltopdf --enable-internal-links -L 10mm -R 9.5mm -T 10mm -B 9.5mm Chapter2.html Chapter2.pdf

./cpdf Chapter1.pdf Chapter2.pdf -o Ebook.pdf 

I wrote a script that automates this process and coverts Ebook to EPUB, AZW3 and PDF. You can read more about it here: https://towardsdatascience.com/transform-jupyter-notebook-to-an-ebook-ef3a9d32ac4f.