如何使用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 教师闺蜜祝福语简短