0

I'm trying to create PDF reports with cakephp3 and doompdf but the pdf is not being generated, just the html.

bootstrap.php:

Plugin::load('Dompdf');

routes.php:

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

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

});

'controller:'

  public function pdf() {

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

'view:'

<?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>

The HTML is being generated as expected, but the pdf is not. Can anyone please explain why?

André
  • 1
  • 2

1 Answers1

0

try to do that:

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

After installation, did you generate a symbolic link?

// In a shell
bin/cake plugin assets symlink
E. Biagi
  • 452
  • 3
  • 12
  • I made the changes but still not generating the pdf, I generated the symbolic link gave some deprecated errors but in the end gave the message "copied assets to directory ... Done" – André Mar 03 '21 at 22:48
  • Vi sua pergunta lá no grupo do cake no Facebook. Eu utilizo a engine WkHtmlToPdf. É bem simples de utilizar. Caso considere utilizar: https://github.com/FriendsOfCake/CakePdf – E. Biagi Mar 04 '21 at 04:34