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

85,419

Solution 1

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

Solution 2

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

Solution 3

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.

Solution 4

I am learning python today, and I met the same problem, lately I set the windows enviroment variables and everything is OK.
I add the install path of wkhtml to the path, for example:"D:\developAssistTools\wkhtmltopdf\bin;" is my install path of wkhtml, and I add it to the path, everything is OK.

import pdfkit
pdfkit.from_url("http://google.com", "out.pdf")

finally, I find a out.pdf.

Solution 5

import pdfkit
path_wkthmltopdf = b'C:\Program Files\wkhtmltopdf\\bin\wkhtmltopdf.exe'
config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf)
pdfkit.from_url("http://google.com", "rajul-url.pdf", configuration=config)
pdfkit.from_file("output.xml","rajul-pdf.pdf", configuration=config)

The Above Code block is working perfectly fine for me. Please note that file which needs to be converted is in the same directory where the pdf file is creating.

Share:
85,419

Related videos on Youtube

Arun Prakash
Author by

Arun Prakash

Updated on July 09, 2022

Comments

  • Arun Prakash
    Arun Prakash almost 2 years

    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')
    
  • Max
    Max almost 7 years
    You also need to add it to the PATH on Windows according to the pdfkit wiki link here github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopd‌​f
  • Korzak
    Korzak over 5 years
    This is a godsend....I have been struggling to get Weasyprint or PyQT5 to do something like this for a day. This is so simple. Thank you!
  • Alexander
    Alexander over 4 years
    Just to make it obvious to readers who might not have admin rights, you do not need to actually run the wkhtmltopdf installer after downloading, you can just unzip the .exe and then point to the \bin\wkhtmltopdf.exe file inside the unzipped .exe. For me (on a Windows machine without privileges) this was the most suitable of all the Python html-to-pdf solutions I tested (I also tried weasyprint and xhtml2pdf).
  • elano7
    elano7 over 4 years
    For those who use VS code, restart VS Code or maybe just the Terminal. After inserting the Environment variable. I got errors but after restarting VS Code it worked.
  • Davidson Lima
    Davidson Lima over 2 years
    Worked like a charm to me, running with Spyder from Anaconda3.
  • Michael Larsson
    Michael Larsson about 2 years
    Yes it worked. I first missed the configuration=config, but when added it created the pdf. Thanks magical.