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

前端 未结 10 1882
灰色年华
灰色年华 2020-12-01 06:37

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\\         


        
相关标签:
10条回答
  • 2020-12-01 07:08

    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.

    0 讨论(0)
  • 2020-12-01 07:08

    When I tried all of the above methods, I was till facing Permission Error as I don't have the admin rights to my workstation. If that's the case for you too, then make sure when you install your wkhtmltopdf.exe. The destination folder for installation is in your python site-packages folder, or add the directory to sys.path. Normally it gets installed in Program files folder. I changed the installation directory and this works for me:

    import pdfkit
    pdfkit.from_url("http://google.com", "out.pdf")
    
    0 讨论(0)
  • 2020-12-01 07:09

    Found the decode on a windows platform needed to be a binary string, try:

            path_wkthmltopdf = b'C:\Program Files\wkhtmltopdf\\bin\wkhtmltopdf.exe'
            config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf)
            pdfkit.from_url(url=urlpath, output_path=pdffilepath,configuration=config)
    
    0 讨论(0)
  • 2020-12-01 07:12

    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.

    0 讨论(0)
提交回复
热议问题