문제

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) 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top