简体   繁体   English

Pdfkit / wkhtmltopdf-OSError:[Errno 8] Exec格式错误

[英]Pdfkit/wkhtmltopdf - OSError: [Errno 8] Exec format error

Please look at the below error trace. 请查看下面的错误跟踪。

In [1]: import pdfkit

In [2]: pdfkit.from_string('a', 'a.pdf')
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
 in ()
----> 1 pdfkit.from_string('a', 'a.pdf')

/root/.virtualenvs/v1/lib/python2.7/site-packages/pdfkit/api.pyc in from_string(input, output_path, options, toc, cover, css, configuration)
     66                configuration=configuration)
     67 
---> 68     return r.to_pdf(output_path)
     69 
     70 

/root/.virtualenvs/v1/lib/python2.7/site-packages/pdfkit/pdfkit.pyc in to_pdf(self, path)
     91 
     92         result = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
---> 93                                   stderr=subprocess.PIPE)
     94 
     95         # If the source is a string then we will pipe it into wkhtmltopdf.

/usr/lib/python2.7/subprocess.pyc in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags)
    708                                 p2cread, p2cwrite,
    709                                 c2pread, c2pwrite,
--> 710                                 errread, errwrite)
    711         except Exception:
    712             # Preserve original exception in case os.close raises.

/usr/lib/python2.7/subprocess.pyc in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, to_close, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite)
   1325                         raise
   1326                 child_exception = pickle.loads(data)
-> 1327                 raise child_exception
   1328 
   1329 

OSError: [Errno 8] Exec format error

Not sure if this is an issue or some fault from my side, it was working in my local system(installed long back) but not working in digital ocean server. 我不确定这是问题还是某些故障,它在我的本地系统中工作(安装很久),但在Digital Ocean Server中却不工作。 Both are Ubuntu 14. 两者都是Ubuntu 14。

I followed instructions from this page - http://fedir.github.io/web/blog/2013/09/25/install-wkhtmltopdf-on-ubuntu/ 我按照此页面上的说明进行操作-http://fedir.github.io/web/blog/2013/09/25/install-wkhtmltopdf-on-ubuntu/

Note that I was able to generate pdfs using terminal commands but not using pdfkit. 请注意,我能够使用终端命令生成pdf,但无法使用pdfkit。

Please let me know if I missed anything. 如果我错过了任何事情,请告诉我。

Update - Solution from this link is working for me. 更新-此链接的解决方案对我有用。

As @user1305989's comment, following is the solution, 正如@ user1305989的评论,以下是解决方案,

Steps: 脚步:

  1. At first install xvfb server: 首先安装xvfb服务器:

     sudo apt-get install xvfb 
  2. Get needed version of wkhtmltopdf from http://wkhtmltopdf.org/downloads.html . http://wkhtmltopdf.org/downloads.html获取所需的wkhtmltopdf版本。

    For Ubuntu 14.04 64-bit: 对于Ubuntu 14.04 64位:

     wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2.1/wkhtmltox-0.12.2.1_linux-trusty-amd64.deb 
  3. Install wkhtmltopdf: 安装wkhtmltopdf:

     sudo dpkg -i wkhtmltox-0.12.2.1_linux-trusty-amd64.deb 

    Install dependency (if needed): 安装依赖项(如果需要):

     sudo apt-get -f install 
  4. Create symblic link in /usr/local/bin/ : /usr/local/bin/创建符号链接:

     echo 'exec xvfb-run -a -s "-screen 0 640x480x16" wkhtmltopdf "$@"' | sudo tee /usr/local/bin/wkhtmltopdf.sh >/dev/null sudo chmod a+x /usr/local/bin/wkhtmltopdf.sh 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM