Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
817 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')
question from:https://stackoverflow.com/questions/27673870/cant-create-pdf-using-python-pdfkit-error-no-wkhtmltopdf-executable-found

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

1 Answer

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').


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...