Skip to content

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

Open
@Lorenzo-Care

Description

@Lorenzo-Care

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

  • PHP Version: 7.3.33
  • PHPWord Version: ^0.18.2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions