我大家
我使用PHPWORD创建.docx文件没有任何问题
现在我要转换在.pdf文件中创建的.docx文件
我尝试这个简单的脚本,但不能在我的配置上使用:
\PhpOffice\PhpWord\Settings::setPdfRendererPath('/PDF/tcpdf.php');
\PhpOffice\PhpWord\Settings::setPdfRendererName('TCPDF');
$phpWord = new \PhpOffice\PhpWord\PhpWord();
//Open template and save it as docx
$document = $phpWord->loadTemplate('edited8.docx');
$document->saveAs('temp.docx');
//Load temp file
$phpWord = \PhpOffice\PhpWord\IOFactory::load('temp.docx');
//Save it
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord , 'PDF');
$xmlWriter->save('result.pdf');
我收到此错误
遇到未捕获的异常键入:PhpOffice \ PhpWord \ Exception \ Exception
消息:PDF渲染库或库路径尚未定义。
文件名:/application/php_word/vendor/phpoffice/phpword/src/PhpWord/Writer/PDF.php
行号:50
有人可以帮助我吗?非常感谢
您需要设置PDF渲染器。您在使用CodeIgniter吗?是我在CodeIgniter中的代码:
$rendererName = Settings::PDF_RENDERER_DOMPDF;
$rendererLibraryPath = APPPATH.('vendor/dompdf/dompdf');
Settings::setPdfRenderer($rendererName, $rendererLibraryPath);
我正在使用DomPDF ..只需自定义$ rendererName和$ rendererLibraryPath。也许是正确的...