我正在尝试实现此插件https://github.com/ceeram/CakePdf
在我的视图方法中,我添加了此代码
public function view($id = null) {
$this->User->id = $id;
$this->autoRander="false";
if (!$this->User->exists()) {
throw new NotFoundException(__('Invalid user'));
}
$this->pdfConfig = array(
'orientation' => 'portrait',
'filename' => 'User_' . $id
);
$this->set('user', $this->User->read(null, $id));
}
我也添加了
Configure::write('CakePdf', array(
'engine' => 'CakePdf.WkHtmlToPdf',
'options' => array(
'print-media-type' => false,
'outline' => true,
'dpi' => 96
),
'margin' => array(
'bottom' => 15,
'left' => 50,
'right' => 30,
'top' => 45
),
'orientation' => 'landscape',
'download' => true
));
现在的问题是,当我尝试执行此代码时,我发现此错误 wkhtmltopdf二进制文件未找到或无法执行:/ usr / bin / wkhtmltopdf 我已安装wkhtmltopdf。在CakePdf插件代码中,他们使用了
protected $binary = '/usr/bin/wkhtmltopdf';
如何使用此引擎解决此问题?如何确定此路径?
答案 0 :(得分:2)
我遇到了同样的问题。在我的Mac上,正确的路径为/usr/local/bin/wkhtmltopdf
。
要覆盖默认路径,我在Configure::write
块中添加了一行:
Configure::write('CakePdf', array(
'binary' => '/usr/local/bin/wkhtmltopdf', // set the correct path here
'engine' => 'CakePdf.WkHtmlToPdf',
'options' => array(
'print-media-type' => false,
'outline' => true,
'dpi' => 96
),
'margin' => array(
'bottom' => 15,
'left' => 50,
'right' => 30,
'top' => 45
),
'orientation' => 'landscape',
'download' => true
));
答案 1 :(得分:1)
如果您正在使用MAMP更改
// app/Plugin/CakePdf/Pdf/Engine/WkHtmlToPdfEngine.php
protected $binary = '/usr/bin/wkhtmltopdf';
到
// app/Plugin/CakePdf/Pdf/Engine/WkHtmlToPdfEngine.php
protected $binary = '/usr/local/bin/wkhtmltopdf';
答案 2 :(得分:0)
whereis wkhtmltopdf
。