试图创建使用PHP和包装phpwkhtmltopdfphpwkhtmltopdf - 无法创建PDF - 失败没有错误消息
require '../vendor/autoload.php';
use mikehaertl\wkhtmlto\Pdf;
// You can pass a filename, a HTML string or an URL to the constructor
$pdf = new Pdf('http://www.google.co.uk');
// On some systems you may have to set the binary path.
//$pdf->binary = 'C:\pdf';
$pdf->send('google.pdf');
if (!$pdf->send()) {
throw new Exception('Could not create PDF: '.$pdf->getError());
}
但得到的错误
Fatal error: Uncaught exception 'Exception' with message 'Could not create PDF: Failed without error message: wkhtmltopdf "http://google.com" "C:\Windows\Temp\tmp4047.tmp.pdf"' in C:\wamp\www\site\ajax\createpdf.php on line 24
又去到c PDF文件:\ windows \ temp并可以看到文件tmp4047.tmp.pdf - 但已损坏并且不会加载
已经运行在命令行wkhtmltopdf没有问题 - PDF创建OK
wkhtmltopdf http://google.com google.pdf
编辑 - 使用snappy代替 - 做工精细,有没有人得到这个在AWS弹性魔豆的工作?任何教程? TQ
//snappy
use Knp\Snappy\Pdf;
$snappy = new Pdf('C://"Program Files"/wkhtmltopdf/bin/wkhtmltopdf.exe');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="file.pdf"');
echo $snappy->getOutput('http://www.google.co.uk');
注 - Windows用户提出报价一轮“程序文件”
可能是一个权限问题。尝试捕捉该异常并打印堆栈跟踪,然后使用跟踪浏览wkhtmltopdf的源代码,并确切地查看它崩溃的位置。 –
嗨 - 确定你是对的,但尝试不同的包更快 – zima10101