如何使用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 春节初二祝福语简短