Dompdf class Dompdf [duplicate]

1

I'm having trouble generating pdf with Dompdf using MVC. I'm using the following code:

// Importa arquivo de config da classe DOMPDF
require_once 'bower_components/dompdf/dompdf_config.inc.php';


// reference the Dompdf namespace
// use Dompdf\Dompdf;

// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml('Hello World!');

// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');

// Render the HTML as PDF
$dompdf->render();

// Get the generated PDF file contents
$pdf = $dompdf->output();

// Output the generated PDF to Browser
$dompdf->stream('testePDF.pdf');

The result is the following error: Fatal error:

Class 'Dompdf' not found

When I use the following line:

// reference the Dompdf namespace
use Dompdf\Dompdf;    

The result is this:

Parse error: syntax error, unexpected 'use' (T_USE)
    
asked by anonymous 20.01.2016 / 12:35

1 answer

0

Hello, try this:

// Importa arquivo de config da classe DOMPDF
require_once 'bower_components/dompdf/dompdf_config.inc.php';
// reference the Dompdf namespace
// use Dompdf\Dompdf;

// instantiate and use the dompdf class
$dompdf = new \Dompdf();
//resto do código
    
20.01.2016 / 13:01