Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:\Python27\pdfcre", line 13, in <module>
    pdfkit.from_url('http://google.com', 'out.pdf')
  File "C:\Python27\lib\site-packages\pdfkit\api.py", line 22, in from_url
    configuration=configuration)
  File "C:\Python27\lib\site-packages\pdfkit\pdfkit.py", line 38, in __init__
    self.configuration = (Configuration() if configuration is None
  File "C:\Python27\lib\site-packages\pdfkit\configuration.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\\wkhtmltopdf\bin\\wkhtmltopdf.exe')
pdfkit.from_url('http://google.com', 'out.pdf')
like image 943
Arun Prakash Avatar asked Dec 28 '14 05:12

Arun Prakash


3 Answers

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

import pdfkit
path_wkhtmltopdf = r'C:\Program Files (x86)\wkhtmltopdf\bin\wkhtmltopdf.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)\wkhtmltopdf\bin\wkhtmltopdf.exe').

like image 111
kadee Avatar answered Oct 13 '22 02:10

kadee


Please install wkhtmltopdf using,

sudo apt install -y wkhtmltopdf

for windows machine install it from below link, http://wkhtmltopdf.org/downloads.html

and you need to add wkhtmltopdf path into environment variables

like image 24
Mohideen bin Mohammed Avatar answered Oct 13 '22 03:10

Mohideen bin Mohammed


IOError: 'No wkhtmltopdf executable found'

Make sure that you have wkhtmltopdf in your $PATH or set via custom configuration. where wkhtmltopdf in Windows or which wkhtmltopdf on Linux should return actual path to binary.

Adding this configuration line worked for me:

config = pdfkit.configuration(wkhtmltopdf="C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe")
pdfkit.from_string(html, 'MyPDF.pdf', configuration=config)

From github

Seems you need to pass configuration=config as argument.

like image 13
Rutrus Avatar answered Oct 13 '22 02:10

Rutrus