<?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');
/** * Exports the complete report as a DOCX file * @return boolean False on error * @todo use unoconv */ public function exportCompleteReportDOC($data) { $_course = api_get_course_info(); $filename = 'gb_results_' . $_course['code'] . '_' . gmdate('YmdGis'); $filepath = api_get_path(SYS_ARCHIVE_PATH) . $filename; //build the results $inc = api_get_path(LIBRARY_PATH) . 'phpdocx/classes/CreateDocx.inc'; require_once api_get_path(LIBRARY_PATH) . 'phpdocx/classes/CreateDocx.inc'; $docx = new CreateDocx(); $paramsHeader = array('font' => 'Courrier', 'jc' => 'left', 'textWrap' => 5); $docx->addHeader(get_lang('FlatView'), $paramsHeader); $params = array('font' => 'Courrier', 'border' => 'single', 'border_sz' => 20); $lines = 0; $values[] = implode("\t", $data[0]); foreach ($data[1] as $line) { $values[] = implode("\t", $line); $lines++; } //$data = array(); //$docx->addTable($data, $params); $docx->addList($values, $params); //$docx->addFooter('', $paramsHeader); $paramsPage = array('orient' => 'landscape'); $docx->createDocx($filepath, $paramsPage); //output the results $data = file_get_contents($filepath . '.docx'); $len = strlen($data); //header("Content-type: application/vnd.ms-word"); header('Content-type: application/vnd.openxmlformats-officedocument.wordprocessingml.document'); //header('Content-Type: application/force-download'); header('Content-length: ' . $len); header("Content-Disposition: attachment; filename=\"{$filename}.docx\""); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0,pre-check=0'); header('Pragma: public'); echo $data; return true; }
<?php //path to the CreateDocx class within your PHPDocX installation require_once '../../../classes/CreateDocx.inc'; $docx = new CreateDocx(); //Date in the header $options_1 = array('bold' => true, 'fontSize' => 12, 'color' => 'b70000', 'dateFormat' => 'dd/MM/yyyy H:mm:ss'); $date = new WordFragment($docx); $date->addDateAndHour($options_1); $docx->addHeader(array('default' => $date)); $docx->addText('Let us include now different examples of the addDateAndHour with different date formatting:'); $options_2 = array('textAlign' => 'center', 'bold' => true, 'fontSize' => 14, 'color' => '333333', 'dateFormat' => "dd' of 'MMMM' of 'yyyy' at 'H:mm"); $docx->addDateAndHour($options_2); $options_3 = array('bold' => true, 'fontSize' => 11, 'color' => '0000FF', 'dateFormat' => "MM'-'dd'-'yy"); $docx->addDateAndHour($options_3); $docx->createDocx('example_addDateAndHour_1');
<?php /** * Create a DOCX file. Header * * @category Phpdocx * @package examples * @subpackage intermediate * @copyright Copyright (c) 2009-2011 Narcea Producciones Multimedia S.L. * (http://www.2mdc.com) * @license LGPL * @version 2.0 * @link http://www.phpdocx.com * @since File available since Release 2.0 */ require_once '../../classes/CreateDocx.inc'; $docx = new CreateDocx(); $paramsHeader = array('font' => 'Times New Roman', 'jc' => 'right', 'textWrap' => 5); $docx->addHeader('Header text', $paramsHeader); $docx->createDocx('example_header');
<?php /** * Create a DOCX file. Header and footer with font styles * * @category Phpdocx * @package examples * @subpackage intermediate * @copyright Copyright (c) 2009-2011 Narcea Producciones Multimedia S.L. * (http://www.2mdc.com) * @license LGPL * @version 2.0 * @link http://www.phpdocx.com * @since File available since Release 2.0 */ require_once '../../classes/CreateDocx.inc'; $docx = new CreateDocx(); $paramsHeader = array('name' => '../files/img/image.png', 'jc' => 'right', 'textWrap' => 5, 'font' => 'Arial'); $docx->addHeader('Header Arial', $paramsHeader); $paramsHeader = array('font' => 'Times New Roman'); $docx->addHeader('Header Times New Roman', $paramsHeader); $paramsFooter = array('pager' => 'true', 'pagerAlignment' => 'center', 'font' => 'Arial'); $docx->addFooter('Footer Arial', $paramsFooter); $docx->createDocx('example_header_and_footer');
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')); //add some text in the first page of the document $docx->addText('Now some text in the second page.'); $docx->createDocx('example_addHeader_2');
<?php //path to the CreateDocx class within your PHPDocX installation require_once '../../../classes/CreateDocx.inc'; $docx = new CreateDocx(); //create a Word fragment to insdert in the default header $numbering = new WordFragment($docx, 'defaultHeader'); //sert some formatting options $options = array('textAlign' => 'right', 'bold' => true, 'sz' => 14, 'color' => 'B70000'); $numbering->addPageNumber('numerical', $options); $docx->addHeader(array('default' => $numbering)); //Now we include a couple of pages to better illustrate the example $docx->addText('This is the first page.'); $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_addPageNumber_1');