Cakephp error: Class 'mPDF' not found

Asked

Viewed 377 times

0

I installed mPDF by the prompt on the Friends Of Cake github, and followed the instructions as on the github, but it is giving mPDF class error not found and line error $mpdf = new mPDF();, giving as no file or directory found even if there is the file, do not know how to solve!

Gerarpdf.ctp

    <?php
    include ('/Plugin/mpdf/src/Mpdf.php');
    
        $pagina = 
            "<html>
                <body>
                    <h1>Relatório de lead cadastrado</h1>
                    <ul>
                        <li>[email protected]</li>
                        <li>[email protected]</li>
                        <li>[email protected]</li>
                    </ul>
                    <h4>http://www.celke.com.br</h5>
                </body>
            </html>
            ";
    
    $arquivo = "Cadastro.pdf";
    
    
    $mpdf = new mPDF();
    $mpdf->WriteHTML($pagina);
    
    $mpdf->Output($arquivo, 'I');
    
    // I - Abre no navegador
    // F - Salva o arquivo no servido
    // D - Salva o arquivo no computador do usuário
    ?>

Controller

    namespace App\Controller;
    
    use App\Controller\AppController;
    use Cake\ORM\TableRegistry;
    class RelatoriosController extends AppController
    {
    
        public function GerarPdf()
        {
            $this -> pdfConfig = array (
                'orientation' => 'landscape',
                'download' => true
            );
        }  
    }

1 answer

0


I managed to solve my problem, I had to import the mPDF, so my code was like this:

<?php
namespace Mpdf; //mpf importado
error_reporting(0); //concertando erro de vizualizaçao
ini_set('display_errors', 0);


include ('/Plugin/mpdf/src/Mpdf.php');

    $pagina = 
        "<html>
            <body>
                <h1>Relatório de lead cadastrado</h1>
                <ul>
                    <li>[email protected]</li>
                    <li>[email protected]</li>
                    <li>[email protected]</li>
                </ul>
                <h4>http://www.celke.com.br</h5>
            </body>
        </html>
        ";

$arquivo = "Cadastro.pdf";


$mpdf = new mPDF();
$mpdf->WriteHTML($pagina);

$mpdf->Output($arquivo, 'I');

// I - Abre no navegador
// F - Salva o arquivo no servido
// D - Salva o arquivo no computador do usuário
?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.