Replies: 2   Views: 97
Replaceplaceholderimage not insert image

Posted by dev-info  · 07-07-2020 - 14:21


i tried to replace variable $IMAGE$ by our image COR.jpg, but nothing append.

In the docx , stay $IMAGE$

my code:

        $path_signature =  "C:\\wamp64\\test\\COR.jpg";

        $docx = new Phpdocx\Create\CreateDocxFromTemplate("C:\\wamp64\\test\\test\\BE.docx");

        $docx->replacePlaceholderImage('IMAGE', $path_signature);



Can you help me? thank you

Posted by admin  · 07-07-2020 - 15:08


Using replacePlaceholderImage, the placeholder needs to be added to the alternative text of the image using MS Word or any other DOCX editor. On you can read more information and sampes about using this metod.

If you need to replace a text placeholder by an image, you need to use a WordFragment and replaceVariableByWordFragment:

$image = new WordFragment($docx, 'document');
$image->addImage(array('src' => 'image.png' , 'scaling' => 50, 'float' => 'right', 'textWrap' => 1));

$docx->replaceVariableByWordFragment(array('PLACEHOLDER' => $image ), array('type' => 'block'));

You can read more information about both methods on the following pages of the practical guide:


Posted by dev-info  · 07-07-2020 - 15:17

it's perfect! thank you :)

topic is closed