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

依然范特西╮ 提交于 2019-12-30 05:03:32

问题


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 the code :How to hide code from cells in ipython notebook visualized with nbviewer?
  • I've figre out the way to convert the notebook to slides(html) Is there a way to print a jupyter/ipython notebook slide presentation? This post also suggests how to convert the html to pdf.

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


回答1:


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.



来源:https://stackoverflow.com/questions/38884142/best-way-to-print-jupyter-notebook-slides-how-to-put-a-page-break

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!