Error adding composer (Class not found)

2

I'm getting the following error:

  

Fatal error: Class 'wkhtmltopdf \ Pdf' not found in   /Applications/XAMPP/xamppfiles/htdocs/common/class/PrePagoConsulta.php   online 480

Code snippet:

use wkhtmltopdf\Pdf;

class PrePagoConsulta extends Query
{
    public function gerarPDF($html, $nomeArquivo){

        $pdf = new Pdf($html); // * Linha 480

        if (!$pdf->saveAs($_SERVER['DOCUMENT_ROOT'].'/upload/consultas-pre/'.$nomeArquivo.'.pdf')) {
            echo $pdf->getError();
        }
    }
}

And the folder structure looks like this:

In autoload_psr4.php , I'm setting as follows:

return array(
    'wkhtmltopdf\' => array($vendorDir.'/wkhtmltopdf/src')
);

How can I fix the error? Where am I going wrong? hehe

    
asked by anonymous 31.10.2017 / 15:11

1 answer

2

This scheme is strange, because when it installs it is in the vendor folder, unless you have set it to lib , it seems to me that you did not use the composer to install the packages, but tried installing manually.

If the package you are using is the link , then you have installed something wrong, because the package name is not wkhtmltopdf , but phpwkhtmltopdf (prefixed " php "), then the correct one should be:

use mikehaertl\wkhtmlto\Pdf;

class PrePagoConsulta extends Query
{
    public function gerarPDF($html, $nomeArquivo){

        $pdf = new Pdf($html); // * Linha 480

        if (!$pdf->saveAs($_SERVER['DOCUMENT_ROOT'].'/upload/consultas-pre/'.$nomeArquivo.'.pdf')) {
            echo $pdf->getError();
        }
    }
}

However if you installed manually I really recommend you review this and try to install via command line (which is just what the composer does), do something like:

cd pastadomeuprojeto
composer require mikehaertl/phpwkhtmltopdf

Ready it will do everything manually, so import:

use mikehaertl\wkhtmlto\Pdf;
    
31.10.2017 / 15:17