試圖創建使用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