【问题标题】:path issue for rendering libraries with phpexcel pdf使用 phpexcel pdf 渲染库的路径问题
【发布时间】:2013-12-10 20:24:38
【问题描述】:

我是编程新手,我正在尽力而为。到目前为止,我可以安装 PHPExcel 并可以创建一个包含内容的 .xls 文件,并且工作正常。

我现在要做的是将一些内容放入 PDF 文件中,但没有成功。

错误说我应该设置 $renderName 和 $renderNameLibrary,我这样做了.. 所以我不明白我做错了什么。

我使用 Codeigniter,所以我将 PHPExcel 文件夹复制到 site/application/third_party/ 文件夹中,并将 PHPExcel.php 文件复制到 third_party 中。

然后在 site/application/libraries/ 我包含了这个文件:pdf.php 这是该文件包含的内容的 sn-p:

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

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

我已经在 library/dompdf 中安装了最新的 dompdf 版本

dompdf.php 是我应该为 $rendererLibrary 设置的文件吗?

IOFactory.php所在的路径,是:site/application/third_party/PHPExcel/IOFactory.php

在我的 admin.php 上,我创建了这个函数来测试 pdf 是否正常工作(也使用 phpexcel 文档中的示例 01simple-download-pdf.php):

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');


}

我真的不知道错误在哪里,有人可以帮我吗?

最后编辑: 2013 年 11 月 12 日

【问题讨论】:

    标签: php codeigniter pdf phpexcel


    【解决方案1】:

    $rendererLibraryPath 值需要是实际 tcPDF 库的路径,而不是 PHPExcel 的包装文件的路径......

    PHPExcel 能够找到自己的包装文件,但不知道您在服务器上的哪个位置安装了 tcPDF 库

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-25
      • 2018-08-21
      • 1970-01-01
      • 2018-03-23
      • 1970-01-01
      • 1970-01-01
      • 2020-01-20
      相关资源
      最近更新 更多