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

yipeiwu_com5年前Python基础

问题: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”的问题解答,希望对有需要的网友有所帮助。

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对【听图阁-专注于Python设计】的支持。如果你想了解更多相关内容请查看下面相关链接

相关文章

selenium 多窗口切换的实现(windows)

在web应用中,常常会遇见点击某个链接会弹出一个新的窗口,或者是相互关联的web应用 ,这样要去操作新窗口中的元素,这时就需要主机切换到新窗口进行操作。。WebDriver 提供了swi...

Python小游戏之300行代码实现俄罗斯方块

Python小游戏之300行代码实现俄罗斯方块

前言 本文代码基于 python3.6 和 pygame1.9.4。 俄罗斯方块是儿时最经典的游戏之一,刚开始接触 pygame 的时候就想写一个俄罗斯方块。但是想到旋转,停靠,消除等操...

解决Python安装后pip不能用的问题

解决Python安装后pip不能用的问题

本人电脑上的Python为3.5,安装在Windows上,虽然安装过程中选择了pip,但是在命令行输入pip后仍然不能成功,尝试一下方法,终于解决问题 1、使用下面的语句确保没有报错了...

Python实用技巧之利用元组代替字典并为元组元素命名

前言 本文主要给大家介绍了关于Python利用元组代替字典并为元组元素命名的相关内容,下面话不多说了,来一起看看详细的介绍吧 场景: 一般使用字典定义一个人的姓名,年龄,性别,邮箱等信息...

简单了解python 生成器 列表推导式 生成器表达式

生成器就是自己用python代码写的迭代器,生成器的本质就是迭代器。 通过以下两种方式构建一个生成器: 1、通过生成器函数 2、生成器表达式 生成器函数: 函数 def f...