pdfkit是将html转换为pdf格式文档的python库。
环境准备
- 安装pdfkit
pip install pdfkit
- 安装wkhtmltopdf
1.下载:https://wkhtmltopdf.org/downloads.html
2.将按照目录下的bin添加到环境变量的path中;
3.重启电脑,重启电脑,重启电脑。
pdfkit支持的方法
pdfkit的源码中,代码量不大,可以浏览一下,主要包含以下方法:
pdfkit/api.py
- form_url:传入的参数为url
def from_url(url, output_path, options=None, toc=None,
cover=None,configuration=None, cover_first=False)
- form_file:传入的参数为html文件
def from_file(input, output_path, options=None, toc=None, cover=None, css=None,
configuration=None, cover_first=False)
- form_string:传入的参数为字符串
def from_string(input, output_path, options=None, toc=None, cover=None, css=None,
configuration=None, cover_first=False)
- Configuration:Configuration中传入了wkhtmltopdf参数
网友评论