PHPExcel to PDF issue using domPDF

Topics: Developer Forum, User Forum
Feb 12, 2013 at 8:16 PM
i am tryign to get my head around the PDF set up in order to get it to work but i am getting no where fast.

I keep getting stuck at the
if (!PHPExcel_Settings::setPdfRenderer(....
I have the following settings:
/** Include PHPExcel */
require_once '../classes/PHPExcel/IOFactory.php';
require_once '../classes/PHPExcel.php';

$rendererName = PHPExcel_Settings::PDF_RENDERER_DOMPDF;
$rendererLibrary = 'domPDF0.6.0beta3';
$rendererLibraryPath = dirname(__FILE__). 'libs/classes/dompdf' . $rendererLibrary;

    if (!PHPExcel_Settings::setPdfRenderer(....
Now the 'libs/classes/dompdf/' is the folder where the domPDF code resides and is the complete code from the zip file

I do not understand what part the $rendererLibrary has is it a fiel or folder name if so then there is no file/folder with that name

What can i be missing here??

PHPExcel Version: 1.7.8
DOMPDF Version: dompdf_0-6-0_beta3
MAC M. Lion

Feb 13, 2013 at 8:30 AM
PHPExcel provides a wrapper for each of three different PDF rendering libraries (tcPDF, mPDF and DomPDF),
When specifying which library you want to use, you need to tell PHPExcel two things: which of the three libraries you are using, and where to find that library. These are the two values that you pass to the setPdfRenderer() method.

The first argument identifies which of the three libraries you intend to use, so that PHPExcel knows which of the three wrappers found in Classes/PHPExcel/Writer/PDF to use.
The second argument is the directory path to the Rendering engines root directory.

For simplicity, when I use these settings myself, I create standard PHP variables to use as arguments, rathe rthan passing values directly:
  • $rendererName (pretty obvious) - set to the appropriate rending engine "name" using the constants defined.
  • $rendererLibraryPath - the directory path to the root directory for the library that I use
    Because I've tested with a number of different versions of the various PDF libraries, and hold them all in subdirectories under a common '/php/libraries/PDF/' directory, I also use a $rendererLibrary variable to identify which specific library version I'm testing against. The only place this is used is defining $rendererLibraryPath using a standard PHP concatentaion. It is not necessary, PHPExcel doesn't know or care that the variable exists, nor does DomPDF or any of the other rendering libraries. It is used purely in a concatenation to define the path to the rendering library root directory.
The code you're using to set $rendererLibraryPath is standard PHP concatenation. What you're doing is telling PHPExcel that it's in a folder
If your PDF library is in the folder libs/classes/dompd, then you set
$rendererLibraryPath = dirname(__FILE__). 'libs/classes/dompdf';
Feb 13, 2013 at 8:43 AM
Hi @MarkBaker many thanks for the reply, thats what i thought i tried all possible methods before posting but will give it another try.
Feb 13, 2013 at 9:05 AM
right i have re-jigged some stuff and i am not getting the same error and it outputs a PDF fine.

BUT i here you say, well when I goto open the PDF it gives me an error:
Acrobat could not open '01simple (1).pdf' because it is either not a supported file type or because the file has been damaged...
To Test i am using the PHPExcel '01simple-download-pdf.php' and my code is as follows:
/** Error reporting */
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

//-- get correct path details
$pathDetails = pathinfo(dirname(__FILE__));
$libsPath = $pathDetails['dirname'];
$classPath = $libsPath .'/classes/';

if (PHP_SAPI == 'cli')
    die('This example should only be run from a Web Browser');

/** Include PHPExcel */
    require_once $classPath . 'PHPExcel.php';

//  Change these values to select the Rendering library that you wish to use and its directory location on your server
$rendererName = PHPExcel_Settings::PDF_RENDERER_DOMPDF;
$rendererLibraryPath = $classPath . 'dompdf-master';

// Create new PHPExcel object
$objPHPExcel = new PHPExcel();

// Set document properties
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
                             ->setLastModifiedBy("Maarten Balliauw")
                             ->setTitle("PDF Test Document")
                             ->setSubject("PDF Test Document")
                             ->setDescription("Test document for PDF, generated using PHP classes.")
                             ->setKeywords("pdf php")
                             ->setCategory("Test result file");

// Add some data
            ->setCellValue('A1', 'Hello')
            ->setCellValue('B2', 'world!')
            ->setCellValue('C1', 'Hello')
            ->setCellValue('D2', 'world!');

// Miscellaneous glyphs, UTF-8
            ->setCellValue('A4', 'Miscellaneous glyphs')
            ->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç');

// Rename worksheet

// Set active sheet index to the first sheet, so Excel opens this as the first sheet

if (!PHPExcel_Settings::setPdfRenderer(
    )) {
        'NOTICE: Please set the $rendererName and $rendererLibraryPath values' .
        '<br />' .
        'at the top of this script as appropriate for your directory structure'
// Redirect output to a client’s web browser (PDF)
header('Content-Type: application/pdf');
header('Content-Disposition: attachment;filename="01simple.pdf"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF');
Many Thanks
Feb 13, 2013 at 10:41 AM
Open the resulting file in a text editor. Look for any leading or trailing whitespace (or BOM markers), or any obvious error messages
Feb 13, 2013 at 10:56 AM
Thanks again for this i got the following error:
PHP-font-lib must either be installed via composer or copied to lib/php-font-lib
Which i know what this is as came across it when using the Dompdf as a separate file so got the latest version from dompdf_0-6-0_beta3 and this solved that issue.

So did the same and yup i can produce the pdf now, much appreciated Mark Baker