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

前端 未结 2 383
-上瘾入骨i
-上瘾入骨i 2020-12-17 04:02

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

What I have done so far:

  • I\'ve figured out the way to hide t
相关标签:
2条回答
  • 2020-12-17 04:23

    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.

    0 讨论(0)
  • 2020-12-17 04:28

    I found several places which mentioned including HTML code for the page break in a markdown cell. I got this to work, but only by:

    1. Include HTML for a page break in a markdown cell. The code used was <p style="page-break-after:always;"></p>
    2. Export it to HTML with nbconvert. For this, the command line would be jupyter nbconvert --to html YourNotebook.ipynb
    3. I could then open that static HTML file with Chrome.
    4. Finally, choose print from within Chrome and choose save as PDF.

    I tried other methods such as print when viewing the .ipynb file or using nbconvert to go straight to PDF, but none of that worked. Exporting to HTML and then opening the html and saving as PDF did work.

    0 讨论(0)
提交回复
热议问题