Question

I'm trying to create a html file and then convert this file to a pdf file using wkhtmltopdf http://wkhtmltopdf.org/

inputfilename = "/tmp/inputfile.html" 
outputfilename = "/tmp/outputfile.pdf"
f = open(inputfilename, 'w')
f.write(html)
f.close()
f1 =  open(outputfilename, 'w')    
ret = convert2pdf(f,outputfilename) 
f1.close()

In convert2pdf I'm doing:

def convert2pdf(htmlfilename,outputpdf): import subprocess commands_to_run = ['/wkhtmltopdf-amd64','htmlfilename', 'outputpdf'] subprocess.call(commands_to_run)

Both input/output files are created on the fly. Input file is perfect but output pdf created using wkhtmltopdf is empty. Can you suggest what am I doing wrong.

Was it helpful?

Solution

I think you just have to change

commands_to_run = ['/wkhtmltopdf-amd64','htmlfilename', 'outputpdf']

to

commands_to_run = ['/wkhtmltopdf-amd64', htmlfilename, outputpdf]

and instead of

ret = convert2pdf(f,outputfilename) 

do

ret = convert2pdf(inputfilename, outputfilename) 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top