我正在使用Terrapin从Rails中的命令行执行wkhtmltopdf.
Terrapin::CommandLine.path = "/usr/bin/wkhtmltopdf"
pdfCommand = Terrapin::CommandLine.new("xvfb-run wkhtmltopdf :html_source :pdf_target")
tempHTML = Tempfile.new(["pattern", ".html"])
tempHTML << html
tempPDF = Tempfile.new(["pattern",".pdf"])
pdfCommand.run(html_source: tempHTML.path, pdf_target: tempPDF.path)
它运行,但返回:
QPainter::begin(): Returned false
Error: Unable to write to destination
Exit with code 1, due to unknown error.
我已经确定wkhtmltopdf拥有完全权限,我不确定TerRapin是否与此有关?
编辑:在控制台中运行xvfb-run wkhtmltopdf http://www.example.com test.pdf
符合预期.