使用wkhtmltopdf打印pdf

版权声明:本文为博主原创文章,转载请注明来源。 https://blog.csdn.net/y101101025/article/details/62461115

使用wkhtmltopdf打印pdf,代码如下:

pdfkit.from_string(dstr, pdfdir + cn_filename)

报错如下:

pdfkit.from_string(dstr, pdfdir + cn_filename)
configuration=configuration, cover_first=cover_first)
self.configuration = (Configuration() if configuration is None
'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

意思是没有安装wkhtmltopdf,后来检查了下安装的wkhtmltopdf版本是64的,而python是32的,重新安装wkhtmltopdf32位,安装wkhtmltopdf完成后当然还要重新在配置path环境变量,环境变量实在wkhtmltopdf安装目录的bin目录,
执行之后还是报错:

raise IOError("wkhtmltopdf exited with non-zero code {0}. error:\n{1}".format(exit_code, stderr))
OSError: wkhtmltopdf exited with non-zero code 1. error:

最后还是改成运行cmd命令的方式,测试成功了。

cmd = pdfexe + " url " + pdfdir+cn_filename;
os.system(cmd);

还是想使用from_string的方式,便重新安装了pdfkit,但还是报错,不过可以生成pdf

pip install pdfkit

猜你喜欢

转载自blog.csdn.net/y101101025/article/details/62461115