Forum


Replies: 2   Views: 616
Remove image in textbox
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

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!