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')
f1 =  open(outputfilename, 'w')    
ret = convert2pdf(f,outputfilename) 

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']


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

and instead of

ret = convert2pdf(f,outputfilename) 


ret = convert2pdf(inputfilename, outputfilename)