phpword如何更改标题中的图像位置

时间:2017-11-23 00:13:34

标签: php jquery html phpword

我的图片当前位于页面顶部,代码如下。我想通过在代码中添加marginTop=> 200来降低图像的位置,但它不起作用。事实上,我已经尝试了所有我知道的但都失败了。有谁知道如何在phpword的标题中更改图像的位置?

$header = $section->addHeader();
$header->firstPage();
$header->addImage(
  '../images/logo/AVA-Full-Logo-Grey.jpg',
  array(
    'width'            => 250,
    'wrappingStyle'    => 'square',
    'marginTop'        => 200,
    'positioning'      => 'relative',
    'posHorizontal'    => PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_RIGHT,
    'posHorizontalRel' => 'margin',
    'posVerticalRel'   => 'line',
  )
);

2 个答案:

答案 0 :(得分:0)

以这种方式经过大量的例子后,它对我有用:

$header = $section->addHeader();
$header->addWatermark(JPATH_SITE.'/libraries/PHPWord-master/headerandfooter/image.png', array('width' => 535, 'height' => 535,'marginTop' => round(\PhpOffice\PhpWord\Shared\Converter::cmToPixel(5.25)),'posHorizontal' => 'absolute','posVertical' => 'absolute'));

答案 1 :(得分:0)

$section->addHeader()->addWatermark("./image.png",
array(
    'width' => round(\PhpOffice\PhpWord\Shared\Converter::cmToPixel(0.5842)),
    'height' => round(\PhpOffice\PhpWord\Shared\Converter::cmToPixel(2.1336)),
    'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_ABSOLUTE,
    'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_ABSOLUTE,
    'posVertical' => \PhpOffice\PhpWord\Style\Image::POSITION_ABSOLUTE,
    'marginLeft' => round(\PhpOffice\PhpWord\Shared\Converter::cmToPixel(17)),
    'marginTop' => round(\PhpOffice\PhpWord\Shared\Converter::cmToPixel(-0.5)),
    'wrappingStyle' => 'infront'
));

此代码对我有用。您需要将定位方法设置为“绝对”,然后可以通过更改“ marginLeft”和“ marginTop”参数来调整位置。