Forum


Replies: 4   Views: 3319
Error replacing image header
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 wilmar.gonzalez  · 12-07-2016 - 15:52

Hi, im using the "replaceVariableByWordFragment" to replace image on header. This is my code

$imageLogo = new WordFragment($docx, 'defaultHeader');
    $imageOptLogo = array(
        'src' => $aImagenes['Logo_Empresa'],
        'textWrap' => 0,
        'height' => 50,
        'width' => 50,
    );
    $imageLogo->addImage($imageOptLogo);
    $docx->replaceVariableByWordFragment(array('Logo_Empresa' => $imageLogo), array('target' => 'header', 'type' => 'block'));

But when i open the generated file, the image is broken, if i use this image on document it's ok but when i use de header, doesn't work.

Thanks

Posted by admin  · 12-07-2016 - 18:15

Hello,

Which license and version of phpdocx are you using?

The value 'defaultHeader' is not a valid target, you should use 'header'.

Regards.

Posted by wilmar.gonzalez  · 12-07-2016 - 19:02

Hello, thanks for the reply.

I have the "phpdocx-corporate-4.1: licensed" and doesn't works. If i use the 'header' on "phpdocx-trial-pro-6.0" works, but replace all text on header, not only the tag. For example " Tittle: $image$ ", the method replace all.

Why this doesn't works in verswion 4.1.

Posted by admin  · 13-07-2016 - 05:50

Hello,

Replacing WordFragment in headers feature was added in phpdocx 4.5, so it's not available in phpdocx 4.1, we recommend you to upgrade to the latest version available.

In your code, the whole paragraph is being replaced because you have added:

'type' => 'block'

this is block replacement. You need to use inline replacement or remove this line.

Regards.

Posted by wilmar.gonzalez  · 13-07-2016 - 14:57

Thanks for reply,

 

The solution works for new version.