首页 > 解决方案 > 使用 cakephp 3 和 doompdf 创建 pdf,未生成 pdf

问题描述

我正在尝试使用 cakephp3 和 doompdf 创建 PDF 报告,但没有生成 pdf,只是生成了 html。

bootstrap.php

Plugin::load('Dompdf');

routes.php

 Router::scope('/', function ($routes) {

$routes->extensions(['pdf']);

});

'控制器:'

  public function pdf() {

$this->viewBuilder()
->className('Dompdf.Pdf')
->layout('Dompdf.default')
->options(['config' => [
    'filename' => 'voluntariopdf',
    'render' => 'download',
]]);
}

'看法:'

<?php $this->start('header'); ?>
<p>Header.</p>
<?php $this->end(); ?>

<?php $this->start('footer'); ?>
<p>Footer.</p>
<?php $this->end(); ?>


 <h1>Teste</h1>

<p>Teste</p>

<p>teste</p>

HTML 正在按预期生成,但 pdf 不是。谁能解释一下为什么?

标签: phppdfcakephpcakephp3

解决方案


尝试这样做:

$this->viewBuilder()
    ->className('Dompdf.Pdf')
    ->layout('Dompdf.default')
    ->options(['config' => [
        'upload_filename' => WWW_ROOT.'pdf/mydocument.pdf',
        'render' => 'upload',
]]);

安装后,有没有生成符号链接?

// In a shell
bin/cake plugin assets symlink

推荐阅读