Forum


Replies: 6   Views: 4377
Error generating header and footer
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by blankdemon  · 29-08-2014 - 19:28

Hello, Thank you for you answer. Yes, library was upgraded to 3.7 but error persists. Curiously error happens when we try to open a document generated with Word 2007, it do not occur with Office 2010 version. The error was reported by some of our users. require_once("libs/phpdocx_37/classes/TransformDoc.inc"); require_once("libs/phpdocx_37/classes/CreateDocx.inc"); class Report { private $driver; public function __construct() { $this->driver = new CreateDocx(); $this->driver->modifyPageLayout('letter'); //$this->driver->setEncodeUTF8(); } public function agregaTextoNegrita($texto = NULL, $texto2 = NULL) { $text = array(); $text[] = array( 'text' => $texto, 'b' => 'on', 'font' => 'Arial', 'sz' => 10 ); $text[] = array( 'text' => $texto2, 'font' => 'Arial', 'sz' => 10 ); $this->driver->addText($text); } public function bajar($nombre, $isPDF = FALSE) { if ($isPDF) { $this->driver->createDocx($nombre); // Creating the PDF $document = new TransformDoc(); $document->setStrFile($nombre . '.docx'); $document->generatePDF(); unlink($nombre . '.docx'); } else { $this->driver->createDocxAndDownload($nombre); } } public function crearFooter($texto, $rutaLogoFooter) { $logo = $this->driver->addImage(array('name' => $rutaLogoFooter, 'rawWordML' => true, 'target' => 'defaultFooter', 'textWrap' => 1, 'float' => 'right')); $texto = $this->driver->addText($texto, array('jc' => 'left', 'b' => 'off', 'sz' => 10, 'rawWordML' => true)); $numeroPagina = $this->driver->addPageNumber('numerical', array('jc' => 'center', 'rawWordML' => true)); $logoFooter = $this->driver->createWordMLFragment(array($logo)); $textoFooter = $this->driver->createWordMLFragment(array($texto)); $numPaginaFooter = $this->driver->createWordMLFragment(array($numeroPagina)); $valuesTable = array( array( $textoFooter, $numPaginaFooter, $logoFooter ) ); $options = array('tableWidth' => array('pct', 100), 'size_col' => array(7000, 6000, 7000), 'border' => 0, 'jc' => 'center', 'rawWordML' => true); $footerTable = $this->driver->addTable($valuesTable, $options); $myFooter = $this->driver->createWordMLFragment(array($footerTable)); $this->driver->addFooter(array('default' => $myFooter)); } } function insertaLogo($reporte) { if (file_exists($logo = 'logo.png') !== FALSE) { $reporte->crearFooter('Date: ' . date("d-m-Y H:i"), $logo); } else { $logo = 'logo.png'; $reporte->crearFooter('Date: ' . date("d-m-Y H:i"), 'logo.png'); } } function reporteCantidadStakeholder() { $reporte = new Report(); insertaLogo($reporte); $reporte->agregaTextoNegrita('Report: ', 'Something'); $reporte->bajar('/tmp/FileName'); } reporteCantidadStakeholder(); Thank you from now on. Regards.