python将html转换为pdf,如何使用Python将HTML转换为PDF

Python提供了Pdfcrowd API v2,可将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)将文本存储为PDFimport pdfkit

pdfkit.from_string('my_testpdf ABC','testpdf.pdf')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值