Forum


Replies: 2   Views: 134
Remove image in textbox

Posted by ralfjahr  · 05-01-2023 - 22:00

Hello,

I have an image (identified by a placeholder) in a textbox. When I use the "standard way" [1] to remove it, the textbox also gets deleted. How can I prevent this?

For the moment, my work arround is to wrap it in a $BLOCK_XYZ$ and then remove the block,

Thanks,

Ralf

[1] https://www.phpdocx.com/documentation/snippets/remove-image-contains-placeholder

Posted by admin  · 06-01-2023 - 07:34

Hello,

As a textbox also uses a drawing element, you need to select the textbox tag in the query:

$referenceNode = array(
    'customQuery' => '//w:txbxContent//w:drawing[descendant::wp:docPr[contains(@descr, "$IMAGE$")]]',
);
$docx->removeWordContent($referenceNode);

//w:txbxContent has been added to the query.

If you send a sample DOCX document you are using to contact[at]phpdocx.com we can generate a custom script using it.

Regards.

Posted by ralfjahr  · 26-01-2023 - 15:02

Thank you!