问题
I have two images in the same row and I want to put some space between them.
Currently nothing is working even I try hard to search for solution.
Here is the code:
$section = $phpWord->addSection($PidPageSettings);
$table = $section->addTable();
$logo = 'pearson1' . $clientid . ".png";
$logo2 = 'genesis2' . $clientid . ".png";
// $table = $section->addTable();
// $table->addRow();
// $cell = $table->addCell(20000, array('bgColor' => 'ffffff'));
$table = $section->addTable();
$table->addRow();
$table->addCell(2000, $cellRowSpan)->addImage('pearson1.png',array('width' => '70','height' => '70','valign' => 'left'));
$table->addCell(2000, $cellRowSpan)->addImage('genesis2.png',array('width' => '120','height' => '40'));
回答1:
Use image margin to adjust space between the two images.
marginLeft. Left margin in inches, can be negative.
marginTop. Top margin in inches, can be negative.
In the example is 20, tweak it depending on your needs.
Note about vertical alignment:
valign. Vertical alignment, top, center, both, bottom.
So left is not valid for valign. Moreover it is for cell, not for image.
valign setting should be included in your $cellRowSpan
like:
$cellRowSpan = array('valign' => 'center');
Set alignment for image like: \PhpOffice\PhpWord\SimpleType\Jc::CENTER
as in this example
Tweak width and height if you want to adjust dimension of images.
height. Height in pt.
width. Width in pt.
For example (adjust parameters for your needs):
$table->addCell(2000, $cellRowSpan)->addImage('pearson1.png',array('width' => 70,'height' => 70, 'marginLeft' => 20, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
$table->addCell(2000, $cellRowSpan)->addImage('genesis2.png',array('width' => 210,'height' => 70, 'marginLeft' => 20, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
来源:https://stackoverflow.com/questions/56989339/neither-image-gap-nor-image-alignment-is-working-in-phpword