Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create right floating image in PhpWord

Tags:

php

phpword

I want an image on the right, text on the left floating around the image. The other way round works pretty good, there also is an example for that on the Recipies section in the documentation. However, I did not get this working with images floating on the right. What I tried:

addImage('myimage.png', 
   array(
       'width'=>320, 
       'height'=>240, 
       'align'=>'right',
       'wrappingStyle'=>'square',
       'positioning' => 'absolute'
   )
);

or

addImage('myimage.png', 
   array(
       'width'=>320, 
       'height'=>240, 
       'align'=>'right',
       'wrappingStyle'=>'square',
       'positioning' => 'absolute',
       'posHorizontalRel' => 'margin',
       'posVerticalRel' => 'line'
   )
);

I also experimented with negative image widths etc., but that did not work neither. Unfortunately, documentation on the whole project is really poor, at least at phpword.readthedocs.org.

like image 754
user3205494 Avatar asked Dec 15 '15 10:12

user3205494


1 Answers

I had the same problem too, and there's no answer on the internet to this date. So here's what I came up with:

$section->addImage('image.png', array(
    'width' => 40,
    'height' => 40,
    'wrappingStyle' => 'square',
    'positioning' => 'absolute',
    'posHorizontal'    => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_RIGHT,
    'posHorizontalRel' => 'margin',
    'posVerticalRel' => 'line',
));
like image 193
Tibi Avatar answered Oct 21 '22 13:10

Tibi