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.
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.