如何使用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 元旦适合的祝福语简短
13 朋友出远门祝福语简短
14 初六简短的祝福语
15 祝男孩生日祝福语简短
16 同事调离的祝福语简短
17 拜年红包的祝福语简短
18 妈妈生日祝福语简短励志