泉州专业网站建设,页面设计参考,梅西网页设计作业,网站建设与客户价格谈判技巧一、下载
1、python的imgkit、pdfkit库
pip install imgkit
pip install pdfkit
2、wkhtmltopdf工具包
下载地址#xff1a;https://wkhtmltopdf.org/downloads.html 下载之后安装#xff0c;安装完成会生成两个程序#xff0c;分别用来转图片和pdf#xff1a; 二、使…一、下载
1、python的imgkit、pdfkit库
pip install imgkit
pip install pdfkit
2、wkhtmltopdf工具包
下载地址https://wkhtmltopdf.org/downloads.html 下载之后安装安装完成会生成两个程序分别用来转图片和pdf 二、使用
1、转为图片
import imgkitpath_wkimg rC:\Program Files\wkhtmltopdf/bin\wkhtmltoimage.exe # 工具路径
cfg imgkit.config(wkhtmltoimagepath_wkimg)# 1、将html文件转为图片
imgkit.from_file(r./helloworld.html, helloworld.jpg, configcfg)# 2、从url获取html再转为图片
imgkit.from_url(https://httpbin.org/ip, ip.jpg, configcfg)# 3、将字符串转为图片
imgkit.from_string(Hello!,hello.jpg, configcfg)
2、转为pdf
import pdfkitpath_wkpdf rC:\Program Files\wkhtmltopdf/bin\wkhtmltopdf.exe # 工具路径
cfg pdfkit.configuration(wkhtmltopdfpath_wkpdf)# 1、将html文件转为pdf
pdfkit.from_file(r./helloworld.html, helloworld.pdf, configurationcfg)
# 传入列表
pdfkit.from_file([r./helloworld.html, r./111.html, r./222.html], helloworld.pdf, configurationcfg)# 2、从url获取html再转为pdf
pdfkit.from_url(https://httpbin.org/ip, ip.pdf, configurationcfg)
# 传入列表
pdfkit.from_url([https://httpbin.org/ip,https://httpbin.org/ip], ip.pdf, configurationcfg)# 3、将字符串转为pdf
pdfkit.from_string(Hello!,hello.pdf, configurationcfg)
3、乱码解决
import imgkitoptions {encoding: utf8}
imgkit.from_string(table, table.jpg,optionsoptions)