If you're working on Laravel (or any other framework using composer), you can skip that step ;) It's already in public/index.php
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';
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...!! :)
Please or to participate in this conversation.