问题
I'm currently working with PhpWord. I added a header
section, and inside it, added two images. Images need to be aligned, one left and the other right, but in the same line. And I have this code but only prints the images one below the other, only way I can change them is insde the .docx file.
$header = $section->addHeader();
$header->addImage('http://localhost/doWords/logoRenatea.jpg',
array(
'width' => '291',
'height' => '81',
'align' => 'left',
'marginTop' => -1,
'marginLeft' => -1,
'wrappingStyle' => 'behind'
));
$header->addImage('http://localhost/doWords/logoMTESS.jpg',
array(
'width' => '110',
'height' => '44',
'align' => 'right',
'marginTop' => -1,
'marginLeft' => -1,
'wrappingStyle' => 'infront'
));
Already tried without wrappingStyle, without margins, and not worked. Any ideas?
Output:
Desired:
回答1:
table is an easy way to get your images to the same line
...
$table = $header->addTable(array('width' => '5000', 'unit' => 'pct'));
$table->addRow();
$table->addCell(2000)->addImage(...); // image1 with needed styles
$table->addCell(2000)->addTextRun(array('align' => 'right'))->addImage(...); // image2 with needed styles
回答2:
The problem was that align
does not accept left
or right
values. It prefers start
and end
respectively. But that's not all. I also needed to add position absolute. So here is the code:
$header->addImage('http://localhost/doWords/logoRenatea.jpg',
array(
'width' => '291',
'height' => '81',
'align' => 'start',
'positioning' => 'absolute'
));
$image1 = $header->addImage('http://localhost/doWords/logoMTESS.jpg',
array(
'width' => '110',
'height' => '44',
'align' => 'end'
));
The only thing that I could not manage to get to work are margins, but I aligned the images, that was the main issue.
来源:https://stackoverflow.com/questions/33502891/wrappingstyle-align-image-not-working-in-a-header-section