Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pdfkit OSError: No wkhtmltopdf executable found

I'm trying to convert a webpage to PDF, using pdfkit but it shows following error

Traceback (most recent call last):

  File "<ipython-input-39-33289a2ef087>", line 1, in <module>
runfile('H:/Python/Practice/pdf_read_write.py', wdir='H:/Python/Practice')

  File "C:\Program Files\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile
execfile(filename, namespace)

  File "C:\Program Files\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)

  File "H:/Python/Practice/pdf_read_write.py", line 10, in <module>
config = pdfkit.configuration(wkhtmltopdf="C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe")

  File "C:\Program Files\Anaconda3\lib\site-packages\pdfkit\api.py", line 83, in configuration
return Configuration(**kwargs)

  File "C:\Program Files\Anaconda3\lib\site-packages\pdfkit\configuration.py", line 27, in __init__
'https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf' % self.wkhtmltopdf)

OSError: No wkhtmltopdf executable found: "C:\Program Files\wkhtmltopdin\wkhtmltopdf.exe"
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

I have downloaded wkhtmktopdf from Here and installed. Added the path to environment variable but still shows the same error.
I have tried configuring pdfkit but nothing worked.

Here is my code:

import pdfkit
config = pdfkit.configuration(wkhtmltopdf="C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe")
pdfkit.from_url("http://www.geeksforgeeks.org/convex-hull-set-2-graham-scan/", "out.pdf",configuration=config)

How to solve this issue ??

like image 670
MD. Khairul Basar Avatar asked Feb 23 '17 15:02

MD. Khairul Basar


People also ask

How do I install Wkhtmltopdf?

Windows. Download the latest version of the package from the Wkhtmltopdf project releases page. Uncompress the downloaded archive and add the wkhtmltox\bin directory to your system path. Restart all running servers.


1 Answers

Your config path contains an ASCII Backspace, the \b in \bin, which pdfkit appears to be stripping out and converting C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe to C:\Program Files\wkhtmltopdf\wkhtmltopdf.exe.

This can be resolved by using r, which makes it a raw literal

config_path = r'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe'

or \\

config_path = 'C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe'
like image 69
Wondercricket Avatar answered Dec 10 '22 03:12

Wondercricket