【发布时间】:2014-05-22 04:02:28
【问题描述】:
我一直在尝试使用以下方法将我的 excel 文件保存为 pdf:
PHPExcel - https://github.com/segy/PhpExcel
我的框架是 cakePHP 2.3,我可以成功创建 excel 文件,但保存为 pdf 将无法正常工作。阅读文档,尝试示例,在整个互联网上搜索,但没有骰子。
据我所知,上面的链接由 phpExcel 1.8 和 mPDF 5.4 组成。我正在使用它的 PHPExcel Helper。
我什至无法从 phpexcel 中获取示例。
$rendererName = PHPExcel_Settings::PDF_RENDERER_MPDF;
$rendererLibrary = 'mPDF5.4';
$rendererLibraryPath = dirname(__FILE__).'/../../../libraries/PDF/' . $rendererLibrary;
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'
);
}
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');
如果我只能在 https://github.com/segy/PhpExcel 上使用 PHPExcel 生成一个 hello world pdf,那就太好了。
顺便说一句,我已经可以使用助手生成 .xlsx 文档了,我只需要将它直接渲染为 pdf。
有什么想法吗?
【问题讨论】:
-
您使用的是什么 PDF 渲染引擎? PHPExcel 是否配置为使用它?
-
显示您的代码!并解释到底什么是行不通的。另外请提及 CakePHP、PHPExcel Plugin、PHPExcel 和 mPDF 的版本。
-
更新问题,如果我错过了这么重要的细节,我很抱歉(刚加入stackoverflow,不知道来龙去脉)
标签: cakephp pdf pdf-generation phpexcel mpdf