如何使用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 生日广州男生祝福语简短