PHPExcel和mPDF给我设置Rendername和Path错误

时间:2015-12-31 17:52:58

标签: php phpexcel

我有最新版本的PHPExcel。

根据我的理解,我不需要下载mPDF,因为它已经在PHPExcel中,正确吗?

每次我尝试运行它虽然它告诉我这个错误

  

注意:请设置$ rendererName和$ rendererLibraryPath值   在此脚本的顶部,适合您的目录结构

这对我没有任何意义,因为我已经确定了它们的确切路径。我错过了什么吗?

这是完整的代码。

                    <?php
                include_once 'processor/dbconfig.php';

                /**
                 * PHPExcel
                 *
                 * Copyright (C) 2006 - 2014 PHPExcel
                 *
                 * This library is free software; you can redistribute it and/or
                 * modify it under the terms of the GNU Lesser General Public
                 * License as published by the Free Software Foundation; either
                 * version 2.1 of the License, or (at your option) any later version.
                 *
                 * This library is distributed in the hope that it will be useful,
                 * but WITHOUT ANY WARRANTY; without even the implied warranty of
                 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
                 * Lesser General Public License for more details.
                 *
                 * You should have received a copy of the GNU Lesser General Public
                 * License along with this library; if not, write to the Free Software
                 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
                 *
                 * @category   PHPExcel
                 * @package    PHPExcel
                 * @copyright  Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
                 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
                 * @version    1.8.0, 2014-03-02
                 */

                /** Error reporting */
                error_reporting(E_ALL);
                ini_set('display_errors', TRUE);
                ini_set('display_startup_errors', TRUE);
                date_default_timezone_set('Europe/London');

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

                /** Include PHPExcel */
                require_once 'Classes/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_TCPDF;
                $rendererName = PHPExcel_Settings::PDF_RENDERER_MPDF;
                //$rendererName = PHPExcel_Settings::PDF_RENDERER_DOMPDF;
                //$rendererLibrary = 'tcPDF5.9';
                $rendererLibrary = 'mPDF.php';
                //$rendererLibrary = 'domPDF0.6.0beta3';
                $rendererLibraryPath = 'Classes/PHPExcel/Writer/PDF' . $rendererLibrary;


                // 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
                $objPHPExcel->setActiveSheetIndex(0)
                            ->setCellValue('A1', 'Hello')
                            ->setCellValue('B2', 'world!')
                            ->setCellValue('C1', 'Hello')
                            ->setCellValue('D2', 'world!');

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

                // Rename worksheet
                $objPHPExcel->getActiveSheet()->setTitle('Simple');
                $objPHPExcel->getActiveSheet()->setShowGridLines(false);

                // Set active sheet index to the first sheet, so Excel opens this as the first sheet
                $objPHPExcel->setActiveSheetIndex(0);


                if (!PHPExcel_Settings::setPdfRenderer(
                        $rendererName,
                        $rendererLibraryPath
                    )) {
                    die(
                        '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');
                $objWriter->save('php://output');
                exit;

1 个答案:

答案 0 :(得分:1)

没有!您已设置路径,以便它们指向PHPExcel的mPDF的 包装 ....这没有意义,因为PHPExcel已经知道其PDF包装器的位置。它不知道你在哪里安装了mPDF .....这就是你应该用这些设置告诉PHPExcel的。

相关问题