<?php

//path to  the CreateDocx class within your PHPDocX installation
require_once '../../../classes/CreateDocx.inc';
$docx = new CreateDocxFromTemplate('../../files/TemplateWordFragment_1.docx');
//create the Word fragment that is going to replace the variable
$wf = new WordFragment($docx, 'document');
//create an image fragment
$image = new WordFragment($docx, 'document');
$image->addImage(array('src' => '../../img/image.png', 'scaling' => 50, 'float' => 'right', 'textWrap' => 1));
//and also a link fragment
$link = new WordFragment($docx, 'document');
$link->addLink('link to Google', array('url' => 'http://www.google.es', 'color' => '0000FF', 'u' => 'single'));
//and a footnote fragment
$footnote = new WordFragment($docx, 'document');
$footnote->addFootnote(array('textDocument' => 'here it is', 'textFootnote' => 'This is the footnote text.'));
//combine them to create a paragraph
$text = array();
$text[] = $image;
$text[] = array('text' => 'I am going to write a link: ', 'b' => 'on');
$text[] = $link;
$text[] = array('text' => ' to illustrate how to include links. ');
$text[] = array('text' => ' As you may see is extremely simple to do so and can be done with any other Word element. For example to include  a footnote is also as simple as this: ');
$text[] = $footnote;
$text[] = array('text' => ' , as you see there is a footnote at the bootom of the page. ', 'color' => 'B70000');
//insert all the content in the Word fragment we are going to use for replacement
$wf->addText($text);
$docx->replaceVariableByWordFragment(array('WORDFRAGMENT' => $wf), array('type' => 'block'));
$docx->createDocx('example_replaceVariable ByWordFragment_1');
<?php

//path to  the CreateDocx class within your PHPDocX installation
require_once '../../../classes/CreateDocx.inc';
$docx = new CreateDocx();
//Create a Word fragment with an image to be inserted in the header of the document
$imageOptions = array('src' => '../../img/image.png', 'dpi' => 300);
$default = new WordFragment($docx, 'defaultFooter');
$default->addImage($imageOptions);
$first = new WordFragment($docx, 'firstFooter');
$first->addText('first page footer.');
$even = new WordFragment($docx, 'evenFooter');
$even->addText('even page footer.');
$docx->addFooter(array('default' => $default, 'first' => $first, 'even' => $even));
//add some text
$docx->addText('This is the first page of a document with different footers for the first and even pages.');
$docx->addBreak(array('type' => 'page'));
$docx->addText('This is the second page.');
$docx->addBreak(array('type' => 'page'));
$docx->addText('This is the third page.');
$docx->createDocx('example_addFooter_2');
    laoreet sapien, feugiat viverra justo dictum eu. Cras at eros ac 
    urna accumsan varius. Vestibulum cursus gravida sollicitudin. 
    Donec vestibulum lectus id sem malesuada volutpat. Praesent et ipsum orci. 
    Sed rutrum eros id erat fermentum in auctor velit auctor. 
    Nam bibendum rutrum augue non pellentesque. Donec in mauris dui, 
    non sagittis dui. Phasellus quam leo, ultricies sit amet cursus nec, 
    elementum at est. Proin blandit volutpat odio ac dignissim. 
    In at lacus dui, sed scelerisque ante. Aliquam tempor, 
    metus sed malesuada vehicula, neque massa malesuada dolor, 
    vel semper massa ante eu nibh.');
//create a simple Word fragment to insert into the table
$textFragment = new WordFragment($docx);
$text = array();
$text[] = array('text' => 'Fit text and ');
$text[] = array('text' => 'Word fragment', 'bold' => true);
$textFragment->addText($text);
//stablish some row properties for the first row
$trProperties = array();
$trProperties[0] = array('minHeight' => 1000, 'tableHeader' => true);
$col_1_1 = array('rowspan' => 4, 'value' => '1_1', 'backgroundColor' => 'cccccc', 'borderColor' => 'b70000', 'border' => 'single', 'borderTopColor' => '0000FF', 'borderWidth' => 16, 'cellMargin' => 200);
$col_2_2 = array('rowspan' => 2, 'colspan' => 2, 'width' => 200, 'value' => $textFragment, 'backgroundColor' => 'ffff66', 'borderColor' => 'b70000', 'border' => 'single', 'cellMargin' => 200, 'fitText' => 'on', 'vAlign' => 'bottom');
$col_2_4 = array('rowspan' => 3, 'value' => 'Some rotated text', 'backgroundColor' => 'eeeeee', 'borderColor' => 'b70000', 'border' => 'single', 'borderWidth' => 16, 'textDirection' => 'tbRl');
//set teh global table properties
$options = array('columnWidths' => array(400, 1400, 400, 400, 400), 'border' => 'single', 'borderWidth' => 4, 'borderColor' => 'cccccc', 'borderSettings' => 'inside', 'float' => array('align' => 'right', 'textMargin_top' => 300, 'textMargin_right' => 400, 'textMargin_bottom' => 300, 'textMargin_left' => 400));
$values = array(array($col_1_1, '1_2', '1_3', '1_4', '1_5'), array($col_2_2, $col_2_4, '2_5'), array('3_5'), array('4_2', '4_3', '4_5'));
$docx->addTable($values, $options, $trProperties);
$docx->addText('In pretium neque vitae sem posuere volutpat. 
    Class aptent taciti sociosqu ad litora torquent per conubia nostra, 
    per inceptos himenaeos. Quisque eget ultricies ipsum. Cras vitae suscipit 
    erat. Nullam fermentum risus sed urna fermentum placerat laoreet arcu lobortis. 
    Integer nisl erat, vehicula eget posuere id, mollis fermentum mi. 
<?php

//path to  the CreateDocx class within your PHPDocX installation
require_once '../../../classes/CreateDocx.inc';
$docx = new CreateDocx();
//create a simple Word fragment with formatted text to be include in the textbox
$txtboxContent = new WordFragment($docx);
$runs = array();
$runs[] = array('text' => 'This text is normal.');
$runs[] = array('text' => ' And this text is red.', 'color' => 'FF0000');
$txtboxContent->addText($runs);
$textBoxOptions = array('align' => 'right', 'paddingLeft' => 5, 'width' => 140, 'height' => 140, 'contentVerticalAlign' => 'bottom');
$txtbx = new WordFragment($docx);
$txtbx->addTextBox($txtboxContent, $textBoxOptions);
$documentText = 'Text in the main document flow. Lorem ipsum dolor sit amet, consectetur adipisicing elit, ' . 'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut ' . 'enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut' . 'aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit ' . 'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut ' . 'enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut' . 'aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit ' . 'in voluptate velit esse cillum dolore eu fugiat nulla pariatur.';
$textRuns = array();
$textRuns[] = $txtbx;
$textRuns[] = array('text' => $documentText);
$docx->addText($textRuns);
$docx->createDocx('example_addTextBox_3');
<?php

//path to  the CreateDocx class within your PHPDocX installation
require_once '../../../classes/CreateDocx.inc';
$docx = new CreateDocx();
//we prepare some formatted text for insertion in the list
$textData = new WordFragment($docx);
$text = array();
$text[] = array('text' => 'We insert some ');
$text[] = array('text' => 'bold text', 'b' => 'on');
$textData->addText($text);
//and also some simple HTML to illustrate the fexibility of the method
$htmlData = new WordFragment($docx);
$html = '<i>Some HTML code</i> with a <a href="http://www.phpdocx.com">link</a>';
$htmlData->embedHTML($html);
$itemList = array('In this example we use a custom list (val = 5) that comes bundled with the default PHPdocX template.', array($textData, 'Line B', 'Line C'), $htmlData, 'Line 3');
//we set the style type to 5: other predefined Word list style
$docx->addList($itemList, 5);
$docx->createDocx('example_addList_3');
<?php

//path to  the CreateDocx class within your PHPDocX installation
require_once '../../../classes/CreateDocx.inc';
$docx = new CreateDocx();
//create a Word fragment with an image to be inserted in the header of the document
$imageOptions = array('src' => '../../img/image.png', 'dpi' => 600);
$headerImage = new WordFragment($docx, 'defaultHeader');
$headerImage->addImage($imageOptions);
//create a Word Fragment with a text
$textOptions = array('fontSize' => 13, 'b' => 'on', 'color' => '567899');
$headerText = new WordFragment($docx, 'defaultHeader');
$headerText->addText('PHPDocX Header Title', $textOptions);
//create a Word Fragment with page numbering
$pageNumberOptions = array('textAlign' => 'right', 'fontSize' => 11);
$headerPageNumber = new WordFragment($docx, 'defaultHeader');
$headerPageNumber->addPageNumber('numerical', $pageNumberOptions);
//create a Word Fragment with a table that will hold all elements
//Warning: we include an additional border none property to the table cells to improve
//PDF rendering
$valuesTable = array(array(array('value' => $headerImage, 'vAlign' => 'center'), array('value' => $headerText, 'vAlign' => 'center'), array('value' => $headerPageNumber, 'vAlign' => 'center')));
$widthTableCols = array(700, 7500, 500);
$paramsTable = array('border' => 'nil', 'columnWidths' => $widthTableCols);
$headerTable = new WordFragment($docx, 'defaultHeader');
$headerTable->addTable($valuesTable, $paramsTable);
//add some text to the body of the document
$docx->addHeader(array('default' => $headerTable));
//add some text in the first page of the document
$docx->addText('This document has a header with an image, some text and page numbering.');
//add a page break so we see the numbering at work
$docx->addBreak(array('type' => 'page'));