TAGS :Viewed: 9 - Published at: a few seconds ago

[ Creating files on the fly and converting to pdf ]

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.

Answer 1


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)