douchuituo3032 2013-12-10 20:24
浏览 93
已采纳

使用phpexcel pdf渲染库的路径问题

i'm new to programming and i'm trying my best. So far i could install PHPExcel and could create a .xls file with content and it's working fine.

What i'm trying to do now is to put some content in a PDF file, with no success.

The error says that i should set the $renderName and the $renderNameLibrary, i did that.. so i don't understand what i'm doing wrong.

I use Codeigniter, so i copied PHPExcel folder into site/application/third_party/ folder and also copied the file PHPExcel.php in third_party.

Then on site/application/libraries/ i included this file: pdf.php and this is a snippet of what this file contains:

require_once APPPATH."/third_party/PHPExcel/IOFactory.php"; 

$rendererName = PHPExcel_Settings::PDF_RENDERER_DOMPDF;
$rendererLibrary = 'dompdf';
$rendererLibraryPath = dirname(__FILE__).'/libraries/dompdf' . $rendererLibrary;

i have installed the latest dompdf version in libraries/dompdf

is dompdf.php the file that i should set for $rendererLibrary?

the path where IOFactory.php is, is: site/application/third_party/PHPExcel/IOFactory.php

on my admin.php i have this function that i've created in order to test if pdf is working (using also the example 01simple-download-pdf.php from phpexcel documentation):

public function exportToPdf(){

    $this->load->library('pdf');

    $this->pdf->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");

    $this->pdf->setActiveSheetIndex(0)
        ->setCellValue('A1', 'Hello')
        ->setCellValue('B2', 'world!')
        ->setCellValue('C1', 'Hello')
        ->setCellValue('D2', 'world!');


    $filename=$rDate.'_Reporte_Usuarios_front'.'.pdf'; 
            header('Content-Type: application/pdf');
            header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
            header('Cache-Control: max-age=0'); //no cache
            // $objWriter = new PHPExcel_Writer_PDF($objPHPExcel);
            $objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'PDF'); 
            $objWriter->setSheetIndex(0);
            $objWriter->save('php://output');


}

I don't really know where is the error, can anyone please help me?

LAST EDIT: 11/12/2013

  • 写回答

1条回答 默认 最新

  • duannian3494 2013-12-11 09:44
    关注

    The $rendererLibraryPath value needs to be the path to the actual tcPDF library, not to PHPExcel's wrapper file....

    PHPExcel is capable of finding its own wrapper file, but has no idea where on your server you've installed the tcPDF library

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?