1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > html转pdf错误wkhtmltopdf

html转pdf错误wkhtmltopdf

时间:2022-01-02 16:19:09

相关推荐

html转pdf错误wkhtmltopdf

本人环境配置

wkhtmltopdf: 0.12.3.2Python: 3.5.2+

问题描述

options = {'encoding': "UTF-8",'custom-header': [('Accept-Encoding', 'gzip')]}pdfkit.from_file(['0.html', '1.html'], 'demo.pdf', options=options)

在将多个html文件转换成pdf的时候, 提示:

This version of wkhtmltopdf is build against an unpatched version of QT

发现下面错误有时候pdf已经转换出来 try下 延时下就可以了

except:print'-------------xxxxx-----------' time.sleep(2)

Traceback (most recent call last):File "/path/to/jekyll_spider.py", line 148, in <module>main()File "/path/to/jekyll_spider.py", line 144, in mainsave_pdf(html_paths, file_name)File "/path/to/jekyll_spider.py", line 118, in save_pdfpdfkit.from_file(html_path, pdf_path, options=options)File "/usr/local/lib/python3.5/dist-packages/pdfkit/api.py", line 49, in from_filereturn r.to_pdf(output_path)File "/usr/local/lib/python3.5/dist-packages/pdfkit/pdfkit.py", line 156, in to_pdfraise IOError('wkhtmltopdf reported an error:\n' + stderr)OSError: wkhtmltopdf reported an error:Error: This version of wkhtmltopdf is build against an unpatched version of QT, and does not support more then one input document.Exit with code 1, due to unknown error.

解决方法

下载并使用 0.12.4 版本的wkhtmltopdf1

$ wget /wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz$ tar xvJf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz$ sudo cp wkhtmltox/bin/wkhtmlto* /usr/bin/

如果使用PDFkit而没有安装wkhtmltopdf, 则会报如下错误:

Traceback (most recent call last):File "/path/to/jekyll_spider.py", line 148, in <module>main()File "/path/to/jekyll_spider.py", line 144, in mainsave_pdf(html_paths, file_name)File "/path/to/jekyll_spider.py", line 118, in save_pdfpdfkit.from_file(html_path, pdf_path, options=options)File "/usr/local/lib/python3.5/dist-packages/pdfkit/api.py", line 47, in from_fileconfiguration=configuration, cover_first=cover_first)File "/usr/local/lib/python3.5/dist-packages/pdfkit/pdfkit.py", line 42, in __init__self.configuration = (Configuration() if configuration is NoneFile "/usr/local/lib/python3.5/dist-packages/pdfkit/configuration.py", line 27, in __init__'/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 - /JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf

Ubuntu可以直接命令行安装wkhtmltopdf:

$ sudo apt-get install wkhtmltopdf

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。