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

yipeiwu_com6年前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设计】的支持。如果你想了解更多相关内容请查看下面相关链接

相关文章

详解Django中六个常用的自定义装饰器

装饰器作用 decorator是当今最流行的设计模式之一,很多使用它的人并不知道它是一种设计模式。这种模式有什么特别之处? 有兴趣可以看看Python Wiki上例子,使用它可以...

python实现对列表中的元素进行倒序打印

python实现对列表中的元素进行倒序打印

1.案例要求: """有列表["a", "d", "f", "j","z","Z","1"],对列表进行倒序,打印结果为["1","Z","z","j","f","d",""a]""...

Python实现的求解最大公约数算法示例

本文实例讲述了Python实现的求解最大公约数算法。分享给大家供大家参考,具体如下: 使用Python求解两个数的最大公约数的时候用到了前面介绍的分解质因式。其实,我写分解质因式程序的时...

Python中的hypot()方法使用简介

 hypot()方法返回的欧几里德范数 sqrt(x*x + y*y). 语法 以下是hypot()方法的语法: hypot(x, y) 注意:此函数是无法直接访问的...

实例讲解Python3中abs()函数

Python3 abs() 函数 描述 abs() 函数返回数字的绝对值。 语法 以下是 abs() 方法的语法: abs( x ) 参数 x-- 数值表达式,可以是整数,浮点...