2014-03-14 00:04:52 +07:00
|
|
|
<?php
|
2014-03-15 22:39:57 +07:00
|
|
|
include_once 'Sample_Header.php';
|
2014-03-14 00:04:52 +07:00
|
|
|
|
|
|
|
|
// New Word document
|
2015-01-01 20:41:42 +04:00
|
|
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
2014-03-23 10:32:08 +04:00
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
2014-03-14 00:04:52 +07:00
|
|
|
|
|
|
|
|
// Begin code
|
2014-04-02 11:02:56 +07:00
|
|
|
$section = $phpWord->addSection();
|
2016-06-04 20:06:37 +04:00
|
|
|
$section->addText('Local image without any styles:');
|
2014-03-14 00:04:52 +07:00
|
|
|
$section->addImage('resources/_mars.jpg');
|
|
|
|
|
$section->addTextBreak(2);
|
2014-04-12 22:49:23 +07:00
|
|
|
|
2016-06-04 20:06:37 +04:00
|
|
|
$section->addText('Local image with styles:');
|
2015-10-10 19:22:19 +04:00
|
|
|
$section->addImage('resources/_earth.jpg', array('width' => 210, 'height' => 210, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
|
2014-03-14 00:04:52 +07:00
|
|
|
$section->addTextBreak(2);
|
|
|
|
|
|
2014-04-12 22:49:23 +07:00
|
|
|
// Remote image
|
2014-03-14 00:04:52 +07:00
|
|
|
$source = 'http://php.net/images/logos/php-med-trans-light.gif';
|
2016-06-04 20:06:37 +04:00
|
|
|
$section->addText("Remote image from: {$source}");
|
2014-03-30 01:17:22 +07:00
|
|
|
$section->addImage($source);
|
2014-03-14 00:04:52 +07:00
|
|
|
|
2017-01-29 13:16:54 +01:00
|
|
|
// Image from string
|
|
|
|
|
$source = 'resources/_mars.jpg';
|
|
|
|
|
$fileContent = file_get_contents($source);
|
|
|
|
|
$section->addText("Image from string");
|
|
|
|
|
$section->addImage($fileContent);
|
|
|
|
|
|
2014-04-12 22:49:23 +07:00
|
|
|
//Wrapping style
|
|
|
|
|
$text = str_repeat('Hello World! ', 15);
|
|
|
|
|
$wrappingStyles = array('inline', 'behind', 'infront', 'square', 'tight');
|
|
|
|
|
foreach ($wrappingStyles as $wrappingStyle) {
|
|
|
|
|
$section->addTextBreak(5);
|
2016-06-04 20:06:37 +04:00
|
|
|
$section->addText("Wrapping style {$wrappingStyle}");
|
2015-01-01 20:41:42 +04:00
|
|
|
$section->addImage(
|
|
|
|
|
'resources/_earth.jpg',
|
|
|
|
|
array(
|
|
|
|
|
'positioning' => 'relative',
|
|
|
|
|
'marginTop' => -1,
|
|
|
|
|
'marginLeft' => 1,
|
|
|
|
|
'width' => 80,
|
|
|
|
|
'height' => 80,
|
|
|
|
|
'wrappingStyle' => $wrappingStyle,
|
|
|
|
|
)
|
|
|
|
|
);
|
2016-06-04 20:06:37 +04:00
|
|
|
$section->addText($text);
|
2014-04-12 22:49:23 +07:00
|
|
|
}
|
2014-03-14 00:04:52 +07:00
|
|
|
|
2014-05-04 22:34:37 +02:00
|
|
|
//Absolute positioning
|
|
|
|
|
$section->addTextBreak(3);
|
2016-06-04 20:06:37 +04:00
|
|
|
$section->addText('Absolute positioning: see top right corner of page');
|
2014-05-04 22:34:37 +02:00
|
|
|
$section->addImage(
|
|
|
|
|
'resources/_mars.jpg',
|
|
|
|
|
array(
|
2015-01-01 20:41:42 +04:00
|
|
|
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3),
|
|
|
|
|
'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3),
|
|
|
|
|
'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_ABSOLUTE,
|
|
|
|
|
'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_RIGHT,
|
2014-05-21 23:53:08 +07:00
|
|
|
'posHorizontalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_PAGE,
|
2015-01-01 20:41:42 +04:00
|
|
|
'posVerticalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_PAGE,
|
|
|
|
|
'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(15.5),
|
|
|
|
|
'marginTop' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(1.55),
|
2014-05-04 22:34:37 +02:00
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
//Relative positioning
|
|
|
|
|
$section->addTextBreak(3);
|
2016-06-04 20:06:37 +04:00
|
|
|
$section->addText('Relative positioning: Horizontal position center relative to column,');
|
|
|
|
|
$section->addText('Vertical position top relative to line');
|
2014-05-04 22:34:37 +02:00
|
|
|
$section->addImage(
|
|
|
|
|
'resources/_mars.jpg',
|
|
|
|
|
array(
|
2015-01-01 20:41:42 +04:00
|
|
|
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3),
|
|
|
|
|
'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3),
|
|
|
|
|
'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE,
|
|
|
|
|
'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_CENTER,
|
2014-05-04 22:34:37 +02:00
|
|
|
'posHorizontalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_COLUMN,
|
2015-01-01 20:41:42 +04:00
|
|
|
'posVertical' => \PhpOffice\PhpWord\Style\Image::POSITION_VERTICAL_TOP,
|
|
|
|
|
'posVerticalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_LINE,
|
2014-05-04 22:34:37 +02:00
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
2014-03-14 00:04:52 +07:00
|
|
|
// Save file
|
2014-04-12 10:12:24 +07:00
|
|
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
|
|
|
|
if (!CLI) {
|
|
|
|
|
include_once 'Sample_Footer.php';
|
2014-03-14 00:04:52 +07:00
|
|
|
}
|