I have a template word document with a placeholder that needs to be replaced by HTML code. That HTML code has test wrapped images as well. Ill break down my requirement and the issue below.
Requirements
- Template has a static first image, headers and footer already configured.
- Multiple templates will be uploaded to system by the user.
- The replacement tag is the body of the template and the HTML content will be designed in a Rich text editor in the UI including formatting and images.
- Added pages should have the headers and footers with new HTML code.
Issue
All the formatting and text wrapping work, but PHPWord doesn't copy the image to the word document. Image is not available inside the media folder and the relationships also not build.

Tried so far
- Saved the HTML code as a separate document and merged it, but the headers and footers are not available in the middle.
- cant use
setImageValuemethod because the user generates the content through Rich Text editor which has mixed with image and text.
Code
$templateProcessor = new TemplateProcessor($templatePath);
$wrapper = new TextBox();
Html::addHtml($wrapper, $this->convertHtmlToXhtml($description));
$xmlWriter = new XMLWriter();
$containerWriter = new Container($xmlWriter, $wrapper, false);
$containerWriter->write();
// Replace the macro parent block with the rendered contents.
$templateProcessor->replaceXmlBlock("description#" . $index, $xmlWriter->getData(), 'w:p');
$templateProcessor->saveAs($outputPath);