wkhtmltopdf - save a html string to PDF in python -
i have html string want store pdf file in python. using pdfkit purpose. below code tried purpose. in below code trying serve image via tornado server.
class mainhandler(requesthandler): def get(self): self.write('hello!') class imagehandler(requesthandler): def get(self): d={} d["mov1"]=1 d["mov2"]=10 d["mov3"]=40 d["mov4"]=3 py.bar(range(len(d)),d.values(),align="center") py.xticks(range(len(d)),d.keys()) io=stringio() py.savefig(io,format='svg') self.set_header("content-type", "image/svg+xml") print io.getvalue() config = pdfkit.configuration(wkhtmltopdf='e:\\wkhtmltopdf\\bin') pdfkit.from_string(io.getvalue(),"e:\\hello.pdf",configuration=config) #error here self.write(io.getvalue()) app = application([ url(r"/", mainhandler), url(r"/image",imagehandler) ]) if __name__=="__main__": app.listen(8888) tornado.ioloop.ioloop.instance().start()
i have installed wkhtmltopdf in e drive. getting exception,
error:tornado.application:uncaught exception /image (::1) httpserverrequest(protocol='http', host='localhost:8888', method='get', uri='/image', version='http/1.1', remote_ip='::1', headers={'accept-language': 'en-us,en;q=0.8', 'accept-encoding': 'gzip, deflate, sdch', 'host': 'localhost:8888', 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'user-agent': 'mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, gecko) chrome/39.0.2171.95 safari/537.36', 'connection': 'keep-alive', 'cookie': '_ga=ga1.1.359367893.1418721747', 'if-none-match': '"ee884f005691a9736e5e380cc68cd4c9679bf2a7"'}) traceback (most recent call last): file "c:\python27\lib\site-packages\tornado\web.py", line 1332, in _execute result = method(*self.path_args, **self.path_kwargs) file "e:\eclipse_workspace\visualisation\module1\mod1.py", line 61, in config = pdfkit.configuration(wkhtmltopdf='e:\\wkhtmltopdf\\bin') file "c:\python27\lib\site-packages\pdfkit\api.py", line 79, in configuration return configuration(**kwargs) 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: "e:\wkhtmltopdf\bin" if file exists please check process can read it. otherwise please install wkhtmltopdf - https://github.com/jazzcore/python-pdfkit/wiki/installing-wkhtmltopdf error:tornado.access:500 /image (::1) 246.00ms
while open using other packages. want know mistake doing.
this link says given above error path should set location of wkhtmltopdf binary. thought did. worked me when changed config to
config = pdfkit.configuration(wkhtmltopdf='e:\\wkhtmltopdf\\bin\\wkhtmltopdf.exe')
Comments
Post a Comment