方法一:利用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