I'm trying to install dompdf using composer, I followed the instructions from Installing DOMPDF with Composer
So far I've
In composer.json
...
"require": {
...
"dompdf/dompdf": "~0.6.1"
},
"autoload": {
....
run composer update
require __DIR__.'/../vendor/autoload.php';
def("DOMPDF_ENABLE_AUTOLOAD", true);
to def("DOMPDF_ENABLE_AUTOLOAD", false);
```
use Dompdf\Adapter\CPDF;
use Dompdf\Dompdf;
use Dompdf\Exception;
require_once "vendor/dompdf/dompdf/dompdf_config.inc.php";
class ArticleController extends BaseController {
...
public function downloadPdf(){
$dompdf = new Dompdf();
$dompdf->loadHtml('hello world');
$dompdf->render();
$dompdf->output();
}
}
so now when I try to download pdf, if gives me error:
exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class 'Dompdf\Dompdf' not found'
have I missed any setup step or doing something wrong?
This issue at dompdf github page helped me to solve this error
The latest stable (0.6.1) does not support namespaces and so would not need the use statement in your code. The upcoming release (0.7.0) does include namespace support.
So, I just removed
use Dompdf\Adapter\CPDF;
use Dompdf\Dompdf;
use Dompdf\Exception;
and used new DOMPDF();
instead of new Dompdf();
as with version 0.6.* namespace will not work.