Fatal PHP error with dompdf in drupal 7 site


I am trying to add some dompdf functionality to a Drupal 7 website. I using a composer autoload to load dompdf. In an XAMPP installation on a windows PC dompdf works fine and produces nice pdf files.

I have copied the document root to an EC2 instance on AWS that is running RHEL Linux. Now I am getting a fatal PHP error. I thought it may because the autoload was not working for some reason so I have altered the index.php as follows

define('DRUPAL_ROOT', getcwd());

if(file_exists(DRUPAL_ROOT . '/vendor/autoload.php')) {
  include DRUPAL_ROOT . '/vendor/autoload.php';

This made no difference although I checked the DRUPAL_ROOT was OK and it is /var/www/html which is correct.

I have tried putting

$pdf = new Dompdf();

After the include just to see if we can get past the error stage and I am still getting the fatal error as follows

PHP Fatal error: Class 'Dompdf' not found in /var/www/html/index.php on line 20

It seems to me that the autoload is not working in this environment but I have no clue why.

I am running RHEL on Amazon EC2 with PHP 5.4.16 and I am running Drupal 7

Does anyone else have experience with this sort of issue?






This should work if you specified 0.6 as the target version in composer.json, e.g.:

  "require" : {
    "dompdf/dompdf" : "0.6.*"

If you're using 0.7, currently in beta:

  "require" : {
    "dompdf/dompdf" : "0.7.*@beta"

then you'll first need to reference the namespace before you instantiate the class:

use Dompdf\Dompdf;



Dompdf 0.7 will not work if you are using PHP version 5.4. I don't believe 'USE' was available before PHP version 5.6. I am still trying to get Dompdf to work with PHP version 5.4 as my hosting site only supports PHP 5.3 and 5.4.

People are also looking for solutions to the problem: php - Error Query in old MySQL


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.