| Server IP : 52.9.100.119 / Your IP : 216.73.217.128 Web Server : Apache/2.4.61 (Amazon) OpenSSL/1.0.2k-fips PHP/7.3.30 Phusion_Passenger/5.1.5 System : Linux ip-172-31-9-35 4.14.355-196.618.amzn1.x86_64 #1 SMP Mon Apr 7 17:09:50 UTC 2025 x86_64 User : root ( 0) PHP Version : 7.3.30 Disable Function : exec,passthru,shell_exec,system,popen,proc_open MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /data/html/garlans_live/vendor/phpoffice/phpword/samples/ |
Upload File : |
<?php
include_once 'Sample_Header.php';
// New Word document
echo date('H:i:s'), ' Create new PhpWord object', EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// New section
$section = $phpWord->addSection();
$section->addText('By default, when you insert an image, it adds a textbreak after its content.');
$section->addText('If we want a simple border around an image, we wrap the image inside a table->row->cell');
$section->addText(
'On the image with the red border, even if we set the row height to the height of the image, '
. 'the textbreak is still there:'
);
$table1 = $section->addTable(array('cellMargin' => 0, 'cellMarginRight' => 0, 'cellMarginBottom' => 0, 'cellMarginLeft' => 0));
$table1->addRow(3750);
$cell1 = $table1->addCell(null, array('valign' => 'top', 'borderSize' => 30, 'borderColor' => 'ff0000'));
$cell1->addImage('./resources/_earth.jpg', array('width' => 250, 'height' => 250, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
$section->addTextBreak();
$section->addText("But if we set the rowStyle 'exactHeight' to true, the real row height is used, removing the textbreak:");
$table2 = $section->addTable(
array(
'cellMargin' => 0,
'cellMarginRight' => 0,
'cellMarginBottom' => 0,
'cellMarginLeft' => 0,
)
);
$table2->addRow(3750, array('exactHeight' => true));
$cell2 = $table2->addCell(null, array('valign' => 'top', 'borderSize' => 30, 'borderColor' => '00ff00'));
$cell2->addImage('./resources/_earth.jpg', array('width' => 250, 'height' => 250, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
$section->addTextBreak();
$section->addText('In this example, image is 250px height. Rows are calculated in twips, and 1px = 15twips.');
$section->addText('So: $' . "table2->addRow(3750, array('exactHeight'=>true));");
// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);
if (!CLI) {
include_once 'Sample_Footer.php';
}