我正在尝试使用 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();
在哪里:
- $this->getVendorsPath() 是供应商文件夹的路径,以“/”(斜杠)结尾
- file_get_contents($this->getPublicPath().'file.tmp') :由于内存问题,我不得不将 html 放在一个临时文件中,并在 PDF 播放时调用它。
一旦控制器被调用,$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/