Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

PeterPan's avatar

Dompdf 0.7 on MaatWebsite/Excel Autoloading issue

Where should i put the autoloading thru composer?? Anyone have experience on this?

Install with composer

To install with Composer, simply require the latest version of this package.

composer require dompdf/dompdf
Make sure that the autoload file from Composer is loaded.

// somewhere early in your project's loading, require the Composer autoloader
// see: http://getcomposer.org/doc/00-intro.md
require 'vendor/autoload.php';
0 likes
3 replies
lostdreamer_nl's avatar

If you're working on Laravel (or any other framework using composer), you can skip that step ;) It's already in public/index.php

1 like
PeterPan's avatar

@lostdreamer_nl I kept on getting the following errors.

Installing DomPDF by composer and setting 'driver' => 'DomPDF', I got the following exception:

PHPExcel_Writer_Exception in DomPDF.php line 34: Unable to load PDF Rendering library

    in DomPDF.php line 34
    at include() in ClassLoader.php line 412
Actually it tries to import vendor/dompdf/dompdf/dompdf_config.inc.php file but there is no one. I can use DomPDF directly.

$pdfRendererClassFile = PHPExcel_Settings::getPdfRendererPath() . '/dompdf_config.inc.php';
if (file_exists($pdfRendererClassFile)) {
    require_once $pdfRendererClassFile;
} else {
    throw new PHPExcel_Writer_Exception('Unable to load PDF Rendering library');
}
PeterPan's avatar
PeterPan
OP
Best Answer
Level 1

I found the issue: The issue is due to the PHPOffice/PHPExcel having issues due to changes to DomPDF 0.7 and this impacted Maatwebsite/Excel PDF export capabilities using Dompdf.

PHPOffice/PHPExcel folks are shifting to PHPSpreadsheet so support higher version of PHP. This fix was dropped. One of the solution https://github.com/PHPOffice/PHPExcel/pull/975 due to DomPDF 0.7 changes.

I managed to get the whole thing to work. Sharing this out to avoid folks having the same problem struggling like i did.

My route to do simple testing

Route::get('/testing', function()
{
     $users = \App\User::select('id', 'name', 'email', 'created_at')->get();
    Excel::create('users', function($excel) use($users) {
        $excel->sheet('Sheet 1', function($sheet) use($users) {
            $sheet->fromArray($users);
        });
    })->export('pdf');
});

In this file ,C:\xampp\htdocs\laravel_deletelater\vendor\phpoffice\phpexcel\Classes\PHPExcel\Writer\PDF\DomPDF.php Hardcode the path to point to dompdf autoload.inc.php

$pdfRendererClassFile = 'C:\xampp\htdocs\laravel_deletelater\vendor\dompdf\dompdf\autoload.inc.php';
if (file_exists($pdfRendererClassFile)) {
    require_once $pdfRendererClassFile;
    
} else {
    throw new PHPExcel_Writer_Exception('Unable to load PDF Rendering library');
}

And furtherdown...change to use namespace

        //  Create PDF
        //$pdf = new DOMPDF();
        //$pdf->set_paper(strtolower($paperSize), $orientation);

        $pdf = new \Dompdf\Dompdf();
        $pdf->set_paper(strtolower($paperSize), $orientation);


        $pdf->load_html(
            $this->generateHTMLHeader(FALSE) .
            $this->generateSheetData() .
            $this->generateHTMLFooter()
        );
        $pdf->render();

        //  Write to file
        fwrite($fileHandle, $pdf->output());

        parent::restoreStateAfterSave($fileHandle);
    }

}

At this path: Some of the path are not correct: C:\xampp\htdocs\laravel_deletelater\vendor\dompdf\dompdf\autoload.inc.php

<?php
/**
 * @package dompdf
 * @link    http://dompdf.github.com/
 * @author  Benj Carson <[email protected]>
 * @author  Fabien Ménager <[email protected]>
 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
 */

/**
 * Dompdf autoload function
 *
 * If you have an existing autoload function, add a call to this function
 * from your existing __autoload() implementation.
 *
 * @param string $class
 */
require_once __DIR__ . '/lib/html5lib/Parser.php';
//require_once __DIR__ . '/lib/php-font-lib/src/FontLib/Autoloader.php';
//require_once __DIR__ . '/lib/php-svg-lib/src/autoload.php';

require_once 'C:\xampp\htdocs\laravel_deletelater\vendor\phenx\php-font-lib\src\FontLib\Autoloader.php';
require_once 'C:\xampp\htdocs\laravel_deletelater\vendor\phenx\php-svg-lib\src\autoload.php';

/*
 * New PHP 5.3.0 namespaced autoloader
 */
//require_once __DIR__ . '/src/Autoloader.php';
require_once 'C:\xampp\htdocs\laravel_deletelater\vendor\dompdf\dompdf\src\Autoloader.php';


Dompdf\Autoloader::register();

That's it folks...!! :)

1 like

Please or to participate in this conversation.