<?php //path to the CreateDocx class within your PHPDocX installation require_once '../../../classes/CreateDocx.inc'; $docx = new CreateDocx(); //You should include the relative path to the image you want to use as background $docx->addBackgroundImage('../../img/image.jpg'); //add a paragraph of text $docx->addText('Please, use a discrete background image so the text is easily readable.'); $docx->addText('This one is pretty annoying but it illustrates well the functionality :-)'); $docx->createDocx('example_addBackgroundImage_1');
<?php //path to the CreateDocx class within your PHPDocX installation require_once '../../../classes/CreateDocx.inc'; $docx = new CreateDocx(); //Style options $style = array('color' => '999999', 'border' => 'single', 'borderLeft' => 'double', 'borderColor' => '990000', 'borderRightColor' => '000099', 'borderWidth' => 12, 'borderTopWidth' => 24, 'indentLeft' => 920); //Create custom style $docx->createParagraphStyle('myStyle', $style); //insert a paragraph with that style $text = 'A paragraph in grey color with borders. All borders are red but the right one that is blue. '; $text .= 'The general border style is single but the left border that is double. The top border is also thicker. '; $text .= 'We also include big left indentation.'; $docx->addText($text, array('pStyle' => 'myStyle')); $docx->createDocx('example_createParagraphStyle_1');
function extract_text($file, $file0, $source_type, $url, $chrSet) { global $db_con, $tmp_dir, $pdftotext_path, $catdoc_path, $xls2csv_path, $op_system, $mb, $debug; global $catppt_path, $home_charset, $command_line, $no_log, $clear, $converter_dir, $cl, $index_xmeta; $result = array(); $home_charset1 = str_ireplace('iso-', '', $home_charset); $charset_int = str_ireplace('iso', '', $home_charset1); $temp_file = "tmp_file"; $filename = $tmp_dir . "/" . $temp_file; if ($source_type == 'ods') { $filename .= "." . $source_type . ""; } if ($source_type == 'doc') { $filename .= "." . $source_type . ""; } if ($source_type == 'docx') { $filename .= "." . $source_type . ""; } if ($source_type == 'xlsx') { $filename .= "." . $source_type . ""; } if (!($handle = fopen($filename, 'w'))) { die("Cannot open file {$filename} in temp folder"); } mysqltest(); if (fwrite($handle, $file) === FALSE) { die("Cannot write to file {$filename} in temp folder"); } fclose($handle); mysqltest(); // for PDF documents enter here if ($source_type == 'pdf') { /* include('../converter/pdf2text.php'); $a = new PDF2Text(); $a->setFilename($filename); $a->decodePDF(); echo $a->output(); */ if (!($handle = fopen($pdftotext_path, 'rb'))) { printStandardReport('errorNoPDFConv', $command_line); $result[] = 'ERROR'; } else { // prepare command line for PDF converter if ($op_system != 'win') { $command = "" . $pdftotext_path . " -enc UTF-8 " . $filename . ""; } else { $command = "" . $pdftotext_path . " -cfg xpdfrc " . $filename . " -"; } $a = exec($command, $result, $retval); // convert the PDF document if ($retval != '0') { // error handler for PDF file converter if ($retval == '1' || $retval == '3' || $retval == '127') { if ($retval == '1') { printStandardReport('errorOpenPDF', $command_line); } if ($retval == '3') { printStandardReport('permissionError', $command_line); } if ($retval == '127') { printStandardReport('noConverter', $command_line); } } else { printStandardReport('ufoError', $command_line); } $result[] = 'ERROR'; } $result = implode(' ', $result); } // for DOC and RTF files enter here } else { if ($source_type == 'doc' || $source_type == 'rtf') { /* echo "\r\n\r\n<br /> op_system: '$op_system'<br />\r\n"; echo "\r\n\r\n<br /> catdoc_path: '$catdoc_path'<br />\r\n"; echo "\r\n\r\n<br /> charset_int: '$charset_int'<br />\r\n"; echo "\r\n\r\n<br /> filename: '$filename'<br />\r\n"; */ if ($op_system == 'win') { $command = "" . $catdoc_path . " -s " . $charset_int . " -d utf-8 -x " . $filename . ""; $a = exec($command, $result, $retval); if (stristr($result[0], "catdoc.exe")) { printDocReport($result[0], $cl); } } else { $message = " Indexing of .doc and .rtf documents is currently not supported on LINUX OS."; printDocReport($message, $cl); /* $retval = ''; $catdoc_path = str_ireplace("catdoc.exe", "catdoc.lin", $catdoc_path); //$command = "".$catdoc_path." -cfg xpdfrc ".$filename." -"; $command = "".$catdoc_path." -s ".$charset_int." -d utf-8 -w -x ".$filename.""; $a = exec($command, $result, $retval); // convert the DOC document //echo "\r\n\r\n<br /> retval: '$retval'<br />\r\n"; //echo "\r\n\r\n<br>result Array:<br><pre>";print_r($result);echo "</pre>\r\n"; if ($retval) { $result = 'ERROR'; //echo "\r\n\r\n<br /> retval: '$retval'<br />\r\n"; if($retval == '2') { $message = " File to be converted not found"; printDocReport($message, $cl); } else if($retval == '3') { $message = " Path to file not found."; printDocReport($message, $cl); } else if($retval == '11') { $message = " The executable is corrupted."; printDocReport($message, $cl); } else if($retval == '12') { $message = " Out of memory execution."; printDocReport($message, $cl); } else if($retval == '22') { $message = " dll error"; printDocReport($message, $cl); } else if($retval == '31') { $message = " The association is missing, use Shell to try the OpenWith dialog."; printDocReport($message, $cl); } else if($retval == '32') { $message = " File could not be opened."; printDocReport($message, $cl); } else if($retval == '126') { $message = " Command invoked cannot execute (Permission problem or command is not an executable)."; printDocReport($message, $cl); } else if($retval == 127) { $message = " Command not found."; printDocReport($message, $cl); } else if($retval == 128) { $message = " Invalid argument to exit. Exit takes only integer range 0 – 255."; printDocReport($message, $cl); } else if($retval > 128 && $retval < 255) { $message = " Fatal error code $retval"; printDocReport($message, $cl); } else if($retval == 255) { $message = " Exit status out of range. Exit takes only integer range 0 – 255."; printDocReport($message, $cl); } else { $message = " Unknown error code $retval."; printDocReport($message, $cl); } } */ } // for PPT files enter here } else { if ($source_type == 'ppt') { // currently unsupported,as a failure was encountered for large PowerPoint presentations $a = ''; /* $command = $catppt_path." -s $charset_int -d utf-8 $filename"; $a = exec($command, $result, $retval); */ // for XLS spreadsheets enter here } else { if ($source_type == 'xls') { $error = ''; require_once "" . $converter_dir . "/xls_reader.php"; $data = new Spreadsheet_Excel_Reader(); if ($mb == '1') { // if extention exists, change 'iconv' to mb_convert_encoding: $data->setUTFEncoder('mb'); } // set output encoding. $data->setOutputEncoding('UTF-8'); // read this document $data->read($filename); $error = $data->_ole->error; if ($error == '1') { printStandardReport('xlsError', $command_line, $no_log); $result = 'ERROR'; } else { $result = ''; $boundsheets = array(); $sheets = array(); $boundsheets = $data->boundsheets; // get all tables in this file $sheets = $data->sheets; // get content of all sheets in all tables if ($boundsheets) { foreach ($boundsheets as &$bs) { $result .= "" . $bs['name'] . ", "; // collect all table names in this file } if ($sheets) { foreach ($sheets as &$sheet) { $cells = $sheet['cells']; if ($cells) { // ignore all empty cells foreach ($cells as &$cell) { foreach ($cell as &$content) { $result .= "" . $content . ", "; // collect content of all cells } } } } } if (strtoupper($home_charset) == 'ISO-8859-1') { $result = utf8_encode($result); } } } // for ODS spreadsheets enter here } else { if ($source_type == 'ods') { require_once "" . $converter_dir . "/ods_reader.php"; $reader = ods_reader::reader($filename); $sheets = $reader->read($filename); if ($sheets) { $result = ''; foreach ($sheets as &$sheet) { if ($sheet) { foreach ($sheet as &$cell) { if ($cell) { // ignore all empty cells foreach ($cell as &$content) { $result .= "" . $content . " "; // collect content of all cells } } } } } } else { $result = 'ERROR'; } // for ODT documents enter here } else { if ($source_type == 'odt') { require_once "" . $converter_dir . "/odt_reader.php"; $x = new odt_reader(); // Unzip the document $u = $x->odt_unzip($filename, false); // read the document $result = $x->odt_read($u[0], 2); // create some blanks around the <div> tags $result = str_replace("<", " <", $result); $result = str_replace(">", "> ", $result); //echo "\r\n\r\n<br /> odt result: $result<br />\r\n"; // for DOCX files enter here } else { if ($source_type == 'docx') { // converter class supplied by http://www.phpdocx.com $options = array('paragraph' => false, 'list' => false, 'table' => false, 'footnote' => false, 'endnote' => false, 'chart' => 0); $docx_file = "docx.txt"; $result = ''; require_once "" . $converter_dir . "/docx/CreateDocx.inc"; CreateDocx::DOCX2TXT($filename, $tmp_dir . "/" . $docx_file, $options); if ($file = @file_get_contents($tmp_dir . "/" . $docx_file)) { $result = "{$file} "; } if ($index_xmeta) { require_once "" . $converter_dir . "/xmeta_converter.php"; $docxmeta = new x_metadata(); $docxmeta->setDocument($filename); /* echo "Title : " . $docxmeta->getTitle() . "<br>"; echo "Subject : " . $docxmeta->getSubject() . "<br>"; echo "Creator : " . $docxmeta->getCreator() . "<br>"; echo "Keywords : " . $docxmeta->getKeywords() . "<br>"; echo "Description : " . $docxmeta->getDescription() . "<br>"; echo "Last Modified By : " . $docxmeta->getLastModifiedBy() . "<br>"; echo "Revision : " . $docxmeta->getRevision() . "<br>"; echo "Date Created : " . $docxmeta->getDateCreated() . "<br>"; echo "Date Modified : " . $docxmeta->getDateModified() . "<br>"; */ $result .= $docxmeta->getTitle() . $docxmeta->getSubject() . $docxmeta->getCreator() . $docxmeta->getKeywords() . $docxmeta->getDescription() . $docxmeta->getLastModifiedBy() . $docxmeta->getRevision() . $docxmeta->getDateCreated() . $docxmeta->getDateModified(); } @unlink($tmp_dir . "/" . $docx_file); /* if($result && $chrSet != "UTF-8") { $result = @mb_convert_encoding($result, "UTF-8", $chrSet); } */ // for XLSX spreadsheets enter here } else { if ($source_type == 'xlsx') { $result = ''; $i = 1; $name = ''; $finished = false; $names = array(); require_once "" . $converter_dir . "/xlsx_reader.php"; $xlsx = new SimpleXLSX($filename); $names = $xlsx->sheetNames(); //echo "\r\n\r\n<br>names array:<br><pre>";print_r($names);echo "</pre>\r\n"; if ($debug == 2 && $names) { printXLSXreport(count($names), $cl); } foreach ($names as $my_name) { $result .= $my_name . " "; if ($debug == 2) { printActKeyword($my_name); } } while (!$finished) { // get all sheets if ($rows = $xlsx->rows($i)) { foreach ($rows as $key) { foreach ($key as $val) { if ($val) { $result .= " " . $val; // add value of each cell } } } } else { $finished = true; // no more sheets found } //$my_name = $xlsx->sheetName($i); //echo "\r\n\r\n<br /> sheet name $i: '$my_name'<br />\r\n"; $i++; // try to get next sheet } if ($index_xmeta) { require_once "" . $converter_dir . "/xmeta_converter.php"; $xlscxmeta = new x_metadata(); $xlscxmeta->setDocument($filename); /* echo "Title : " . $xlscxmeta->getTitle() . "<br>"; echo "Subject : " . $xlscxmeta->getSubject() . "<br>"; echo "Creator : " . $xlscxmeta->getCreator() . "<br>"; echo "Keywords : " . $xlscxmeta->getKeywords() . "<br>"; echo "Description : " . $xlscxmeta->getDescription() . "<br>"; echo "Last Modified By : " . $xlscxmeta->getLastModifiedBy() . "<br>"; echo "Revision : " . $xlscxmeta->getRevision() . "<br>"; echo "Date Created : " . $xlscxmeta->getDateCreated() . "<br>"; echo "Date Modified : " . $xlscxmeta->getDateModified() . "<br>"; */ $result .= $xlscxmeta->getTitle() . $xlscxmeta->getSubject() . $xlscxmeta->getCreator() . $xlscxmeta->getKeywords() . $xlscxmeta->getDescription() . $xlscxmeta->getLastModifiedBy() . $xlscxmeta->getRevision() . $xlscxmeta->getDateCreated() . $xlscxmeta->getDateModified(); } /* if($result && $chrSet != "UTF-8") { $result = @mb_convert_encoding($result, "UTF-8", $chrSet); } */ // for JavaScript enter here } else { if ($source_type == 'js') { $result = extract_js($file); } } } } } } } } } if ($result != 'ERROR') { if (is_array($result)) { $result = implode(" ", $result); } $count = strlen($result); if ($count == '0') { // if there was not one word found, print warning message if ($source_type == 'js') { printStandardReport('jsEmpty', $command_line, $no_log); } else { printStandardReport('nothingFound', $command_line, $no_log); } $result = 'ERROR'; } } unlink($filename); mysqltest(); if ($clear == 1) { unset($command, $retval, $a, $file, $count); } return $result; }
<?php /** * Sets the default language of the document. * * @category Phpdocx * @package examples * @subpackage easy * @copyright Copyright (c) Narcea Producciones Multimedia S.L. * (http://www.2mdc.com) * @license LGPL * @version 3.0 * @link http://www.phpdocx.com * @since File available since Release 3.0 */ require_once '../../classes/CreateDocx.inc'; $docx = new CreateDocx(); $docx->setLanguage('es-ES'); $docx->AddText('Este documento tiene el español de España como idioma por defecto (The default document language has been set to Spanish-Spain).'); $docx->createDocx('../docx/example_setLanguage');
<?php //path to the CreateDocx class within your PHPDocX installation require_once '../../../classes/CreateDocx.inc'; $docx = new CreateDocx(); $docx->addText('We will now add a 3D line chart with a title to the Word document:'); $data = array('legend' => array('Series 1', 'Series 2', 'Series 3'), 'data 1' => array(10, 7, 5), 'data 2' => array(20, 60, 3), 'data 3' => array(50, 33, 7), 'data 4' => array(25, 0, 14)); $paramsChart = array('data' => $data, 'type' => 'line3DChart', 'title' => 'Three dimensional line chart', 'color' => '2', 'perspective' => '30', 'rotX' => '30', 'rotY' => '30', 'font' => 'Arial', 'chartAlign' => 'center', 'showTable' => 0, 'sizeX' => '12', 'sizeY' => '10', 'legendPos' => 't', 'legendOverlay' => '0', 'haxLabel' => 'Horizontal label', 'vaxLabel' => 'Vertical label', 'haxLabelDisplay' => 'horizontal', 'vaxLabelDisplay' => 'horizontal', 'hgrid' => '3', 'vgrid' => '1'); $docx->addChart($paramsChart); $docx->addText('And now the same chart in 2D with a different color schem and options:'); $data = array('legend' => array('Series 1', 'Series 2', 'Series 3'), 'data 1' => array(10, 7, 5), 'data 2' => array(20, 60, 3), 'data 3' => array(50, 33, 7), 'data 4' => array(25, 0, 14)); $paramsChart = array('data' => $data, 'type' => 'lineChart', 'color' => '5', 'chartAlign' => 'center', 'showTable' => 0, 'sizeX' => '12', 'sizeY' => '10', 'legendPos' => 'b', 'legendOverlay' => '0', 'haxLabel' => 'X Axis', 'vaxLabel' => 'Y Axis', 'haxLabelDisplay' => 'horizontal', 'vaxLabelDisplay' => 'vertical', 'hgrid' => '3', 'vgrid' => '1'); $docx->addChart($paramsChart); $docx->createDocx('example_addChart_4');
<?php /** * Tutorial example * * @category Phpdocx * @package tutorial * @subpackage easy * @copyright Copyright (c) 2009-2011 Narcea Producciones Multimedia S.L. * (http://www.2mdc.com) * @license http://www.phpdocx.com/wp-content/themes/lightword/pro_license.php * @version 1.8 * @link http://www.phpdocx.com * @since 01/03/2012 */ require_once '../../classes/CreateDocx.inc'; $docx = new CreateDocx(); //Importing header and footer from external .docx file $docx->importHeadersAndFooters('../word_documents/templateHeaderAndFooter.docx'); $text = array(); $text[] = array('text' => 'I am going to write'); $text[] = array('text' => ' Hello World!', 'b' => 'single'); $text[] = array('text' => ' using bold characters.'); $docx->addText($text); //We first prepare an item list element with more sophisticated formatting: $paramsItem = array(array('text' => 'This is the text associated with the first item', 'b' => 'single', 'color' => 'b70000'), array('text' => ' now without bold'), array('text' => ' and blue', 'color' => '0000b7')); $myItem = $docx->addElement('addText', $paramsItem); //Let us now to add a nested unordered list $myList = array($myItem, 'item 2', array('subitem 2_1', 'subitem 2_2'), 'item 3', array('subitem 3_1', 'subitem 3_2', array('sub_subitem 3_2_1', 'sub_subitem 3_2_1')), 'item 4'); $docx->addList($myList, array('val' => 1)); $valuesTable = array(array('cell_1_1', 'cell_1_2', 'cell_1_3', 'cell_1_4'), array('cell_2_1', 'cell_2_2', 'cell_2_3', 'cell_2_4'), array('cell_3_1', 'cell_3_2', 'cell_3_3', 'cell_3_4')); $paramsTable = array('TBLSTYLEval' => 'MediumGrid3-accent5PHPDOCX');
<?php //path to the CreateDocx class within your PHPDocX installation require_once '../../../classes/CreateDocx.inc'; $docx = new CreateDocx(); $text = 'Some text content for the textbox. 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 ' . 'in voluptate velit esse cillum dolore eu fugiat nulla pariatur.'; $textBoxOptions = array('align' => 'right', 'paddingLeft' => 10, 'borderColor' => '#b70000', 'borderWidth' => 4, 'fillColor' => '#dddddd', 'width' => 240); $docx->addTextBox($text, $textBoxOptions); $docx->createDocx('example_addTextBox_1');
<?php require_once '../../../classes/CreateDocx.inc'; $options = array('paragraph' => true, 'list' => true, 'table' => true, 'footnote' => true, 'endnote' => true, 'chart' => 0); CreateDocx::DOCX2TXT('../../files/Text.docx', 'document_1.txt', $options);
<?php /** * Inserts a simple table into the Word document. * * @category Phpdocx * @package examples * @subpackage easy * @copyright Copyright (c) Narcea Producciones Multimedia S.L. * (http://www.2mdc.com) * @license LGPL * @version 3.0 * @link http://www.phpdocx.com * @since File available since Release 3.0 */ require_once '../../classes/CreateDocx.inc'; $docx = new CreateDocx(); $valuesTable = array(array(11, 12), array(21, 22)); $paramsTable = array('border' => 'single', 'border_sz' => 20); $docx->addTable($valuesTable, $paramsTable); $docx->createDocx('../docx/example_table');
/** * 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(); $docx->addText('In this first example we just add an image with a dashed border:'); $options = array('src' => '../../img/image.png', 'imageAlign' => 'center', 'scaling' => 50, 'spacingTop' => 10, 'spacingBottom' => 0, 'spacingLeft' => 0, 'spacingRight' => 20, 'textWrap' => 0, 'borderStyle' => 'lgDash', 'borderWidth' => 6, 'borderColor' => 'FF0000'); $docx->addImage($options); $docx->addText('This is a closing paragraph.'); $docx->createDocx('example_addImage_1');
<?php /** * Create a DOCX file. Two charts in the same DOCX * * @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(); $legends = array('legend1' => array(10, 11, 12), 'legend2' => array(0, 1, 2), 'legend3' => array(40, 41, 42)); $args = array('data' => $legends, 'type' => 'pie3DChart', 'title' => 'Title first chart', 'cornerX' => 20, 'cornerY' => 20, 'cornerP' => 30, 'color' => 2, 'textWrap' => 0, 'sizeX' => 10, 'sizeY' => 10, 'jc' => 'left', 'showPercent' => 1, 'font' => 'Times New Roman'); $docx->addGraphic($args); $legends = array('0' => array('sequence 1', 'sequence 2', 'sequence 3'), 'Category 1' => array(9.300000000000001, 2.4, 2), 'Category 2' => array(2.5, 4.4, 1), 'Category 3' => array(3.5, 1.8, 0.5), 'Category 4' => array(1.5, 8, 1)); $args = array('data' => $legends, 'type' => 'colChart', 'title' => 'Title second chart', 'color' => 2, 'textWrap' => 0, 'sizeX' => 17, 'sizeY' => 7, 'jc' => 'center', 'font' => 'Arial'); $docx->addGraphic($args); $docx->createDocx('example_chart');
<?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(); $docx->addText('We will now add a surface chart to the Word document:'); $data = array('legend' => array('Series 1', 'Series 2', 'Series 3'), 'Value1' => array(4.3, 2.4, 2), 'Value2' => array(2.5, 4.4, 2), 'Value3' => array(3.5, 1.8, 3), 'Value4' => array(4.5, 2.8, 5), 'Value5' => array(5, 2, 3)); $paramsChart = array('data' => $data, 'type' => 'surfaceChart', 'legendpos' => 't', 'legendoverlay' => false, 'sizeX' => 12, 'sizeY' => 8, 'chartAlign' => 'center', 'color' => 2); $docx->addChart($paramsChart); $docx->createDocx('example_addChart_11');
<?php //path to the CreateDocx class within your PHPDocX installation require_once '../../../classes/CreateDocx.inc'; $docx = new CreateDocx(); $footnote = new WordFragment($docx, 'document'); $html = new WordFragment($docx, 'footnote'); //notice the different "target" $htmlCode = '<p>This is some HTML code with a link to <a href="http://www.2mdc.com">2mdc.com</a> and a random image: <img src="../../img/image.png" width="35" height="35" style="vertical-align: middle"></p>'; $html->embedHTML($htmlCode, array('downloadImages' => true)); $footnote->addFootnote(array('textDocument' => 'footnote', 'textFootnote' => $html, 'footnoteMark' => array('customMark' => '*'))); $text = array(); $text[] = array('text' => 'Here comes the '); $text[] = $footnote; $text[] = array('text' => ' and some other text.'); $docx->addText($text); $docx->addText('Some other text.'); $docx->createDocx('example_Footnote_2');
<?php //path to the CreateDocx class within your PHPDocX installation require_once '../../../classes/CreateDocx.inc'; $docx = new CreateDocx(); //Custom options $latinListOptions = array(); $latinListOptions[0]['type'] = 'lowerLetter'; $latinListOptions[0]['format'] = '%1.'; $latinListOptions[1]['type'] = 'lowerRoman'; $latinListOptions[1]['format'] = '%1.%2.'; //Create the list style with name: latin $docx->createListStyle('latin', $latinListOptions); //List items $myList = array('item 1', array('subitem 1.1', 'subitem 1.2'), 'item 2'); //Insert custom list into the Word document $docx->addList($myList, 'latin'); //Save the Word document $docx->createDocx('example_createListStyle_1');
<?php /** * Tutorial example * * @category Phpdocx * @package tutorial * @subpackage easy * @copyright Copyright (c) 2009-2011 Narcea Producciones Multimedia S.L. * (http://www.2mdc.com) * @license http://www.phpdocx.com/wp-content/themes/lightword/pro_license.php * @version 1.8 * @link http://www.phpdocx.com * @since 01/03/2012 */ require_once '../../classes/CreateDocx.inc'; $docx = new CreateDocx(); $text = array(); $text[] = array('text' => 'I am going to write'); $text[] = array('text' => ' Hello World!', 'b' => 'single'); $text[] = array('text' => ' using bold characters.'); $docx->addText($text); $docx->createDocx('../word_documents/hello_world2');
<?php /** * Create a DOCX file. Page example * * @category Phpdocx * @package examples * @subpackage easy * @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(); $text = '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 ' . 'in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ' . 'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui ' . 'officia deserunt mollit anim id est laborum.'; $docx->addText($text); $paramsPage = array('titlePage' => 1, 'orient' => 'normal', 'top' => 4000, 'bottom' => 4000, 'right' => 4000, 'left' => 4000); $docx->createDocx('example_page', $paramsPage);
<?php require_once '../../../classes/CreateDocx.inc'; $docx = new CreateDocx(); $docx->txt2docx('../../files/Text.txt'); $docx->createDocx('example_txt2docx');
<?php /** * Create a DOCX file. Table of contents example * * @category Phpdocx * @package examples * @subpackage easy * @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'; $objDocx = new CreateDocx(); $objDocx->addTableContents('Arial'); $objDocx->createDocx('example_tablecontents');
<?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 CreateDocx(); //parse styles of the default template $docx->parseStyles(); $docx->createDocx('example_parseStyles_1');
<?php //path to the CreateDocx class within your PHPDocX installation require_once '../../../classes/CreateDocx.inc'; $docx = new CreateDocx(); $text = '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 ' . 'in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ' . 'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui ' . 'officia deserunt mollit anim id est laborum.'; $docx->addText($text); $paramsText = array('b' => true); $docx->addText($text, $paramsText); $docx->addSection('nextPage', 'A3'); $docx->addText($text); $paramsText = array('b' => true); $docx->addText($text, $paramsText); $docx->createDocx('example_addSection_1');
<?php //path to the CreateDocx class within your PHPDocX installation require_once '../../../classes/CreateDocx.inc'; $docx = new CreateDocx(); $docx->addHeading('First level title', 0); $text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, ' . 'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'; $docx->addText($text); $docx->addHeading('Second level title', 1); $docx->addText($text); $options = array('color' => 'FF0000', 'textAlign' => 'center', 'fontSize' => 13); $docx->addHeading('Third level title with additional custom formatting', 2, $options); $docx->addText($text); $docx->createDocx('example_addHeading_1');
<?php //path to the CreateDocx class within your PHPDocX installation require_once '../../../classes/CreateDocx.inc'; $docx = new CreateDocx(); $endnote = new WordFragment($docx, 'document'); $endnote->addEndnote(array('textDocument' => 'endnote', 'textEndnote' => 'The endnote we want to insert.')); $text = array(); $text[] = array('text' => 'Here comes the '); $text[] = $endnote; $text[] = array('text' => ' and some other text.'); $docx->addText($text); $docx->addText('Some other text.'); $docx->createDocx('example_addEndnote_1');
<?php //path to the CreateDocx class within your PHPDocX installation require_once '../../../classes/CreateDocx.inc'; $docx = new CreateDocx(); $docx->addText('We write a math equation using MathMML:'); $mathML = '<math xmlns="http://www.w3.org/1998/Math/MathML"> <mrow> <mi>A</mi> <mo>=</mo> <mfenced open="[" close="]"> <mtable> <mtr> <mtd> <mi>x</mi> </mtd> <mtd> <mn>2</mn> </mtd> </mtr> <mtr> <mtd> <mn>3</mn> </mtd> <mtd> <mi>w</mi> </mtd> </mtr> </mtable> </mfenced> </mrow>
<?php //path to the CreateDocx class within your PHPDocX installation require_once '../../../classes/CreateDocx.inc'; $docx = new CreateDocx(); $docx->addText('We are now going to add a paragraph by inserting a chunk of WordML code.'); $wordML = '<w:p><w:r><w:t>A very simple paragraph with only text.</w:t></w:r></w:p>'; $docx->addWordML($wordML); $docx->addText('Beaware that this is not, in general, a recommendable practice unless you are truly familiar with the OOXML standard.'); $docx->createDocx('example_addWordML_1');
<?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');
<?php /** * Create a DOCX file. List example * * @category Phpdocx * @package examples * @subpackage easy * @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(); $valuesList = array('Line 1', 'Line 2', 'Line 3', 'Line 4', 'Line 5'); $paramsList = array('val' => 1); $docx->addList($valuesList, $paramsList); $docx->createDocx('example_list');