Dompdf class Dompdf

Asked

Viewed 551 times

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)
  • This using some framework?

  • what version of your PHP

  • no framework, only MVC and PHP 5.5.12

1 answer

0

Hello, test like 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
  • No way! Still can’t find the class!

  • The strange thing is that it works perfectly on a separate file but does not work within the function!

  • Try to see with file_exists, if it is finding the Dompdf file

Browser other questions tagged

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