Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
855 views
in Technique[技术] by (71.8m points)

api - Can't create pdf using python PDFKIT Error : " No wkhtmltopdf executable found:"

I tried installing pdfkit Python API in my windows 8 machine. I'm getting issues related to path.

Traceback (most recent call last):
  File "C:Python27pdfcre", line 13, in <module>
    pdfkit.from_url('http://google.com', 'out.pdf')
  File "C:Python27libsite-packagespdfkitapi.py", line 22, in from_url
    configuration=configuration)
  File "C:Python27libsite-packagespdfkitpdfkit.py", line 38, in __init__
    self.configuration = (Configuration() if configuration is None
  File "C:Python27libsite-packagespdfkitconfiguration.py", line 27, in __init__
    'https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf' % self.wkhtmltopdf)
IOError: No wkhtmltopdf executable found: ""
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

Is anybody installed Python PDFKIt in windows machine? How to resolve this error.

My sample code :

import pdfkit
import os
config = pdfkit.configuration(wkhtmltopdf='C:\Python27\wkhtmltopdfin\wkhtmltopdf.exe')
pdfkit.from_url('http://google.com', 'out.pdf')
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The following should work without needing to modify the windows environment variables:

import pdfkit
path_wkhtmltopdf = r'C:Program Files (x86)wkhtmltopdfinwkhtmltopdf.exe'
config = pdfkit.configuration(wkhtmltopdf=path_wkhtmltopdf)
pdfkit.from_url("http://google.com", "out.pdf", configuration=config)

Assuming the path is correct of course (e.g. in my case it is r'C:Program Files (x86)wkhtmltopdfinwkhtmltopdf.exe').


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...