PHPOffice / PHPWord

A pure PHP library for reading and writing word processing documents
https://phpoffice.github.io/PHPWord/
Other
7.26k stars 2.7k forks source link

Unable to add <img> tag to Html element #2205

Open Lorenzo-Care opened 2 years ago

Lorenzo-Care commented 2 years ago

Describe the Bug

I'm trying to create a <table> element and add it as Html to my document. In one of the rows I have to add an <img> tag, but I'm unable to do so. Does the library support this functionality?

Steps to Reproduce

<?php
$html .= '<table><tr><td style="width: 50px;"><img src="https://i.imgur.com/Pxh2zYA.jpg" alt="" width="15" height="15"></td></tr></table>';
\PhpOffice\PhpWord\Shared\Html::addHtml($cellTable1Cell3, $html, false, true);

// Save the document
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('/Users/guest/Desktop/testphpword/result/test.docx');

Expected Behavior

I expected the image to show up on the row.

Current Behavior

On document creation I get the following error: Warning: DOMDocument::loadXML(): Opening and ending tag mismatch I've tried closing the image tag like this: <img src="https://i.imgur.com/Pxh2zYA.jpg" alt="" width="15" height="15" /> The warning doesn't show up but I'm unable to open the generated document because it throws an error.

Context

thomasb88 commented 1 year ago

You should debug parseImage on PhpWord\Shared\Html.php

It seems the https://i.imgur.com/Pxh2zYA.jpg content can be downloaded to this part of code.