Python3转换html到pdf的不同解决方案

作者:网络整理 时间:2021-10-03 19:50:03 

问题:python3 如何转换html到pdf

描述:

我的电脑是windows764位,python3.4

我想用python 转换html到pdf.

我尝试了html2pdf,貌似它只支持Python2

我又尝试了wkhtmltox-0.12.2.2_msvc2013-win64和pdfkit,并用下面的例子测试。


import pdfkit
pdfkit.from_url('http://google.com', 'out.pdf')

报错信息


Traceback (most recent call last):
File "E:\Python34\lib\site-packages\pdfkit\configuration.py", line 21, in __init__
 with open(self.wkhtmltopdf) as f:
FileNotFoundError: [Errno 2] No such file or directory: b''
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
 pdfkit.from_url('http://google.com', 'out.pdf')
File "E:\Python34\lib\site-packages\pdfkit\api.py", line 22, in from_url
 c
File "E:\Python34\lib\site-packages\pdfkit\pdfkit.py", line 38, in __init__
 self.configuration = (Configuration() if configuration is None
File "E:\Python34\lib\site-packages\pdfkit\configuration.py", line 27, in __init__
 'https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf' % self.wkhtmltopdf)
OSError: No wkhtmltopdf executable found: "b''"
If this file exists please check that this process can read it. Otherwise please install wkhtmltopdf - https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf

请大神们告诉我,该怎么做呢?

解决方案1:

直接使用里边的wkhtmltopdf即可


wkhtmltopdf http://google.com a.pdf

解决方案2:

把可执行文件的路径加入到环境变量里

以上介绍了“python3 如何转换html到pdf”的问题解答,希望对有需要的网友有所帮助。

来源:http://www.codes51.com/itwd/1185819.html

标签:python,转换,html,pdf
0
投稿

猜你喜欢

  • Keras使用ImageNet上预训练的模型方式

    2021-03-01 10:08:51
  • python不到50行代码完成了多张excel合并的实现示例

    2023-04-11 10:41:39
  • asp如何读取注册表的信息?

    2009-11-19 21:18:00
  • 利用Python求解阿基米德分牛问题

    2023-11-10 09:36:48
  • MySQL数据库常见的出错代码及出错信息

    2008-05-27 12:29:00
  • 仅用500行Python代码实现一个英文解析器的教程

    2022-06-15 02:15:25
  • python自动化测试中装饰器@ddt与@data源码深入解析

    2021-10-08 16:07:14
  • 在ASP.NET 2.0中操作数据之四十四:DataList和Repeater数据排序(三)

    2023-07-02 04:45:57
  • python应用之如何使用Python发送通知到微信

    2022-03-04 01:59:55
  • Oracle常用dump命令,记录一下备查。

    2009-03-04 10:27:00
  • 利用Python上传日志并监控告警的方法详解

    2022-08-23 15:31:01
  • 设计高效的faq页面

    2011-06-10 13:13:00
  • python正则表达式对字符串的查找匹配

    2022-02-21 12:39:50
  • python调用百度AI接口实现人流量统计

    2022-09-10 12:46:27
  • Python脚本传参数argparse模块的使用

    2023-02-28 23:07:21
  • Javascript 获取css属性

    2009-05-31 16:49:00
  • python机器学习实现决策树

    2021-04-21 07:44:34
  • golang中defer的基本使用教程

    2023-07-03 01:19:02
  • 详解Python中的from..import绝对导入语句

    2022-08-10 10:01:33
  • 基于Python制作flappybird游戏的详细步骤

    2023-07-29 10:08:29
  • asp之家 网络编程 m.aspxhome.com