Home > Mobile >  alignment is not working in phpWord TemplateProcessor
alignment is not working in phpWord TemplateProcessor

Time:10-08

I am trying to change the alignment of the image added into the docx file, but the alignment is not working. I have tried as below:

$templateProcessor->setImageValue($tag->template_tag, 
                       array(
                                                        
                          'path' => $filePath, 
                          'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_ABSOLUTE,
                          'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::END,
                         )
                        );

Though the image is rendered in exported docx file, however the image alignment is always left. How can I change the alignment of image to either center or end?

CodePudding user response:

You are using positionning settings reserved when enter image description here ...you got the following replacement (Replaced.docx in the code) enter image description here

If you center the image placeholder... enter image description here ...the replace image is centered ! enter image description here

The second argument, named $replace, of the method setImageValue of the TemplateProcessor class (added in the 0.16 version) can be an associative array but it only supports 3 values (quoted from the docBlock of the method) :

@param mixed $replace Path to image, or array("path" => xx, "width" => yy, "height" => zz)
  • Related