我正在尝试使用WkHtmlToPdf从之前形成的HTML生成PDF,暂时存储在文件中。
$pdf = new WkHtmlToPdf(array('bin' => $this->getVendorsPath() . 'h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64'));
$html = file_get_contents($this->getPublicPath().'file.tmp');
$pdf->addPage($html);
if(!$pdf->saveAs($this->getPublicPath() . 'file.pdf'))
echo "Erro on PDF generating. Error: " . $pdf->getError();
其中:
调用控制器后,$pdf->getError()
给出了错误:
Erro on PDF generating. Error: Could not run command '/var/www/{projects_name}/app/controllers/../../vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64' /tmp/tmp_WkHtmlToPdf_Rgqz5E.html /tmp/tmp_WkHtmlToPdf_qOAH5u: /var/www/{projects_name}/app/controllers/../../vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64: 1: /var/www/{projects_name}/app/controllers/../../vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64: 8: not found /var/www/{projects_name}/app/controllers/../../vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64: 2: /var/www/{projects_name}/app/controllers/../../vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64: Syntax error: ")" unexpected /var/www/{projects_name}/app/controllers/../../vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64: 1: /var/www/{projects_name}/app/controllers/../../vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64: cannot create �A�o��@/�N: Directory nonexistent /var/www/{projects_name}/app/controllers/../../vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64: 1: /var/www/{projects_name}/app/controllers/../../vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64: ELF: not found
很抱歉这一切都在一行中,但我不确定在没有丢失信息的情况下分成小行。
编辑:WkHtmlToPdf的来源=> http://mikehaertl.github.io/phpwkhtmltopdf/