Jupyter导出pdf解决办法

方法一:利用markdown中转

1)jupyter里file -> download as -> markdown(.md)
2)利用本地markdown程序导出pdf这里推荐一个轻量级软件:Typora

https://www.typora.io/

方法二:html转成pdf

把jupyter notebook文件转换成Python支持的html,然后用pdfkit把html转成pdf,会在同目录下生产对应的pdf。
1)python有一个包叫pdfkit,专门用来转换pdf文件

pip install pdfkit

2)下载对应系统的安装包http://wkhtmltopdf.org/

2)编写script脚本

import sys
import subprocess
import pdfkit
inputfile = sys.argv[1].replace(" ","\ ")
temp_html = inputfile[0:inputfile.rfind('.')]+'.html'
command = 'ipython nbconvert --to html ' + inputfile
subprocess.call(command,shell=True)
print '============success==========='
output_file =inputfile[0:inputfile.rfind('.')]+'.pdf'
pdfkit.from_file(temp_html,output_file)
subprocess.call('rm '+temp_html,shell=True)

4)使用:在terminal输入以下代码

python script.py yourfile.ipynb

参考:
1)https://www.jianshu.com/p/49a0c9f74d59
2)https://kuaibao.qq.com/s/20180717A0QNJK00?refer=cp_1026

你可能感兴趣的:(Jupyter导出pdf解决办法)