pdfkit是將html轉(zhuǎn)換為pdf格式文檔的python庫。
環(huán)境準(zhǔn)備
- 安裝pdfkit
pip install pdfkit
- 安裝wkhtmltopdf
1.下載:https://wkhtmltopdf.org/downloads.html
2.將按照目錄下的bin添加到環(huán)境變量的path中久橙;
3.重啟電腦趟薄,重啟電腦涡相,重啟電腦欢峰。
pdfkit支持的方法
pdfkit的源碼中炊邦,代碼量不大芙粱,可以瀏覽一下划咐,主要包含以下方法:
pdfkit/api.py
- form_url:傳入的參數(shù)為url
def from_url(url, output_path, options=None, toc=None,
cover=None,configuration=None, cover_first=False)
- form_file:傳入的參數(shù)為html文件
def from_file(input, output_path, options=None, toc=None, cover=None, css=None,
configuration=None, cover_first=False)
- form_string:傳入的參數(shù)為字符串
def from_string(input, output_path, options=None, toc=None, cover=None, css=None,
configuration=None, cover_first=False)
- Configuration:Configuration中傳入了wkhtmltopdf參數(shù)