我每个人
我没有任何问题创建.docx文件与PHPWORD
现在,我想转换在.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
有人能帮我吗?非常感谢
发布于 2020-05-20 13:02:55
你需要设置PDF渲染器。你在使用CodeIgniter吗?是我用CodeIgniter编写的代码:
$rendererName = Settings::PDF_RENDERER_DOMPDF;
$rendererLibraryPath = APPPATH.('vendor/dompdf/dompdf');
Settings::setPdfRenderer($rendererName, $rendererLibraryPath);
我正在使用DomPDF ..只需自定义$rendererName和$rendererLibraryPath即可。也许这是对的..。
https://stackoverflow.com/questions/61525551
复制相似问题