HTML网页转成PDF
# 教程
https://zhuanlan.zhihu.com/p/94608155
# 示例
# 导入库
import pdfkit
'''将网页url生成pdf文件'''
def url_to_pdf(url, to_file):
# 将wkhtmltopdf.exe程序绝对路径传入config对象
path_wkthmltopdf = r'C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe'
config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf)
# 生成pdf文件,to_file为文件路径
pdfkit.from_url(url, to_file, configuration=config)
print('完成')
# 这里传入url,转换为pdf
url_to_pdf(r'https://www.ruanyifeng.com/blog/2010/05/object-oriented_javascript_encapsulation.html', 'out_2.pdf')
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
去GitHub编辑 (opens new window)
上次更新: 2022/10/21, 22:31:13