如何使用Python将HTML转换为PDF
Python提供了PdfcrowdAPIv2,可将HTML文档转换为PDF。该API非常易于使用,集成仅需要几行代码。
安装
Install the client library from PyPI $ pip install pdfcrowd
从网页/HTML到PDF的以下3个步骤将完成转换
步骤1-下载库pdfkit
$ pip install pdfkit
步骤2-现在下载wkhtmltopdf
对于Ubuntu/Debian-
sudo apt-get install wkhtmltopdf
对于Windows-
(a) Download link : WKHTMLTOPDF (b) Set : PATH variable set binary folder in Environment variables.
第3步-使用Python代码下载-
(i)已保存的HTML页面
import pdfkit
pdfkit.from_file('my_test.html', my_'output.pdf')(ii)按网站网址转换
import pdfkit
pdfkit.from_url('https://www.google.co.in/','my_testpdf.pdf')(iii)将文本存储为PDF
import pdfkit
pdfkit.from_string('my_testpdf ABC','testpdf.pdf')热门推荐
10 诗词送行祝福语大全简短
11 新房开工吉日祝福语简短
12 50多岁生日简短祝福语
13 安徽疫情祝福语简短英语
14 农民朋友发财祝福语简短
15 对生活祝福语简短精辟
16 搬家词简短祝福语朋友
17 女神结婚快乐祝福语简短
18 文学短句祝福语大全简短