我正在使用PHPWord
创建Microsoft Word报告。我基本上从一个模板开始,填充字段并将其保存为单词报告。
我想将此报告转换为pdf文件。我尝试通过PHPWord加载生成的doc文件。但是,当我保存pdf文件时,格式化全部丢失。
以下是我正在使用的代码:
require_once DOC_ROOT . '/vendor/phpoffice/phpword/bootstrap.php';
$path_to_tcpdf = DOC_ROOT . '/includes/plugins/TCPDF/'; // C:\xampp\htdocs\clients\corporate\includes\plugins\TCPDF
\PhpOffice\PhpWord\Settings::setPdfRendererPath($path_to_tcpdf);
\PhpOffice\PhpWord\Settings::setPdfRendererName('TCPDF');
$report_file_doc = DOC_ROOT . '/reports/business_report_U72900GJ2002PTC040573_68628.docx';
$report_file_pdf = DOC_ROOT . '/reports/business_report_U72900GJ2002PTC040573_68628.pdf';
$phpWord = \PhpOffice\PhpWord\IOFactory::load($report_file_doc);
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord , 'PDF');
$xmlWriter->save($report_file_pdf);
知道可能遗漏的是什么吗?
由于
答案 0 :(得分:3)
对于PHPWord foreach ($DSActive in $DSConfig) {Test-Port $hostname $port}
以下是v0.14
渲染器的示例(在v0.13中弃用):
TCPDF
以下是// Require composer autoloder.
require __DIR__.'/vendor/autoload.php';
use PhpOffice\PhpWord\IOFactory;
use PhpOffice\PhpWord\Settings;
// Set PDF renderer.
// Make sure you have `tecnickcom/tcpdf` in your composer dependencies.
Settings::setPdfRendererName(Settings::PDF_RENDERER_TCPDF);
// Path to directory with tcpdf.php file.
// Rigth now `TCPDF` writer is depreacted. Consider to use `DomPDF` or `MPDF` instead.
Settings::setPdfRendererPath('vendor/tecnickcom/tcpdf');
$phpWord = IOFactory::load('document.docx', 'Word2007');
$phpWord->save('document.pdf', 'PDF');
渲染器的示例:
DomPDF
答案 1 :(得分:0)
我不知道我是否正确,但您将文档保存为HTML内容。之后阅读HTML文件内容并在mPDF或tcPdf或fpdf的帮助下将内容写为PDF文件。
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'HTML');