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\\
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.
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.
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
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').
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!
You need set
pdfkit.from_url('http://google.com', 'out.pdf',configuration=config)