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

前端 未结 10 1881
灰色年华
灰色年华 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 06:48
    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.

    0 讨论(0)
  • 2020-12-01 06:48

    No need to write wkhtmltopdf path into code. Just define an environment variable for that, and it works.

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

    For me this code is working.

    0 讨论(0)
  • 2020-12-01 06:53

    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

    0 讨论(0)
  • 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').

    0 讨论(0)
  • 2020-12-01 07:04
    def urltopdf(url,pdffile):
        import pdfkit
        '''
            input
            - url : target url
            - pdffile : target pdf file name
        '''
        path_wkthmltopdf = 'D:\\Program Files (x86)\\wkhtmltopdf\\bin\\wkhtmltopdf.exe'
        config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf)
        #pdfkit.from_url(url=urlpath, output_path=pdffilepath,configuration=config)
        pdfkit.from_url(url,pdffile,configuration=config)
    
    
    urltopdf('http://www.google.com','pdf/google.pdf')
    

    very good solution! thanks everyone!

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

    You need set

    pdfkit.from_url('http://google.com', 'out.pdf',configuration=config)

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