1

I'm trying to generate a PDF from a previous formed HTML, stored temporarilly in a file, with WkHtmlToPdf.

$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();

Where:

  1. $this->getVendorsPath() is a path to the vendor folder, ending with a "/" (slash)
  2. file_get_contents($this->getPublicPath().'file.tmp') : Due to memory issues, I had to put the html in a temp file, and it's called when PDF comes in to play.

Once the controller is called, the $pdf->getError() give me the error bellow:

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

Sorry that's all in one line, but I'm not sure to break into smaller lines without lose information.

EDIT: Source of WkHtmlToPdf => http://mikehaertl.github.io/phpwkhtmltopdf/

Dennis Braga
  • 1,448
  • 3
  • 20
  • 40

0 Answers0