<?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); $headerImage = new WordFragment($docx, 'defaultHeader'); $headerImage->addImage($imageOptions); $docx->addHeader(array('default' => $headerImage)); //add some text $docx->addText('This document has a header with just one image.'); $docx->createDocx('example_addHeader_1');
<?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 $image = new WordFragment($docx); $imageOptions = array('src' => '../../img/image.png', 'scaling' => 50, 'float' => 'right', 'textWrap' => 1); $image->addImage($imageOptions); //create a Word fragment with a link $link = new WordFragment($docx); $linkOptions = array('url' => 'http://www.google.es', 'color' => '0000FF', 'underline' => 'single'); $link->addLink('link to Google', $linkOptions); //create a Word fragment with a footnote $footnote = new WordFragment($docx); $footnote->addFootnote(array('textDocument' => 'here it is', 'textFootnote' => 'This is the footnote text.')); //now we insert the different runs of text with created content and some text $text = array(); $text[] = $image; $text[] = array('text' => 'I am going to write a link: ', 'bold' => true); $text[] = $link; $text[] = array('text' => ' to illustrate how to include links. '); $text[] = array('text' => ' As you may see it is extremely simple to do so and it 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 may check there is a footnote at the bootom of the page. ', 'color' => 'B70000'); $docx->addText($text); $docx->createDocx('example_addText_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' => 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');
<?php //path to the CreateDocx class within your PHPDocX installation require_once '../../../classes/CreateDocx.inc'; $docx = new CreateDocxFromTemplate('../../files/TemplateWordFragment_2.docx'); //create the Word fragment that is going to replace the variable //like the variable to replace is in a footnote we should it as target $wf = new WordFragment($docx, 'footnote'); //create an image fragment $image = new WordFragment($docx, 'footnote'); //Warning: you can not poition absolutely images in footnotes. That is a limitation of the Word interface not the standard. $image->addImage(array('src' => '../../img/image.png', 'scaling' => 10)); //and also a link fragment $link = new WordFragment($docx, 'footnote'); $link->addLink('link to Google', array('url' => 'http://www.google.es', 'color' => '0000FF', 'u' => 'single')); //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 in a footnote. '); $text[] = array('text' => ' As you may see it is extremely simple to do so and can be done with any other Word element.'); //insert all the content in the Word fragment we are going to use for replacement $wf->addText($text); //we want to preserve the reference mark so we do an inline substitution to presereve the paragraph structure. //we also target the footnote that is where the placeholder variable is located $docx->replaceVariableByWordFragment(array('INLINEFRAGMENT' => $wf), array('type' => 'inline', 'target' => 'footnote')); $docx->createDocx('example_replaceVariable ByWordFragment_2');
<?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); $footerImage = new WordFragment($docx, 'defaultFooter'); $footerImage->addImage($imageOptions); $docx->addFooter(array('default' => $footerImage)); //add some text $docx->addText('This document has a footer with just one image.'); $docx->createDocx('example_addFooter_1');
<?php //path to the CreateDocx class within your PHPDocX installation require_once '../../../classes/CreateDocx.inc'; $docx = new CreateDocx(); //we create a few Word fragments to insert rich content in a table $link = new WordFragment($docx); $options = array('url' => 'http://www.google.es'); $link->addLink('Link to Google', $options); $image = new WordFragment($docx); $options = array('src' => '../../img/image.png'); $image->addImage($options); $valuesTable = array(array('Title A', 'Title B', 'Title C'), array('Line A', $link, $image)); $paramsTable = array('tableStyle' => 'LightListAccent1PHPDOCX', 'tableAlign' => 'center', 'columnWidths' => array(1000, 2500, 3000)); $docx->addTable($valuesTable, $paramsTable); $docx->createDocx('example_addTable_2');