【发布时间】:2020-09-27 10:50:43
【问题描述】:
我从 tinymce 获取包含图像和文本(段落)的 html 正文。但是当我尝试将其插入模板时得到空白图像。
这是我的代码:
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('./template.docx');
$section = $phpWord->addSection();
$content = '<p>Test</p> <img src="https://www.sciencemag.org/sites/default/files/styles/inline__450w__no_aspect/public/sparrow_16x9_0.jpg" />';
Html::addHtml($section, $content);
$xml = getXMLContent($section);
\PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(false);
$templateProcessor->setValue('test', $xml);
\PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true);
$templateProcessor->saveAs('./result.docx');
function getXMLContent($section) {
$xmlWriter = new XMLWriter(XMLWRITER::STORAGE_MEMORY, './', Settings::hasCompatibility());
$containerWriter = new Container($xmlWriter, $section);
$containerWriter->write();
return $xmlWriter->getData();
}
我做错了吗?还是有别的办法?
【问题讨论】:
-
尝试将其编码为base64格式。看到这个话题:stackoverflow.com/questions/3967515/…
-
同样的结果。 :(