Forum


Replies: 0   Views: 3304
Docx generation is not consistent each time
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 seb  · 23-01-2015 - 12:23

Hi Guys, I have some example code here for a basic document with a header. The header contains two word fragments - an image and a text box. Sometimes the text box is at the front, and sometimes the image is. It seems to be random each time you generate the docx. The header.jpg file is a simple 72dpi jpeg with dimensions of 3124px x 240px. Could you please take a look and let me know if I'm doing something wrong? Thank you! Here is the code: include_once($_SERVER['DOCUMENT_ROOT']."/library/phpdocx_corporate_4_5/Classes/Phpdocx/Create/CreateDocx.inc"); $docx = new Phpdocx\Create\CreateDocx(); // Header: image $fgmt_bg_image = new \Phpdocx\Elements\WordFragment($docx,'defaultHeader'); $fgmt_bg_image->addImage( array( 'src' => 'header.jpg', 'sizeX' => 500, 'sizeY' => 38, 'float' => 'center', 'textWrap' => 1, 'spacingTop' => 0, 'rawWordML' => true ) ); // Header: text $fgmt_text_box = new \Phpdocx\Elements\WordFragment($docx,'defaultHeader'); $fgmt_text_box->addTextBox( array( "My Document", array( 'b' => 'off', 'jc' => 'right', 'sz' => 12, 'font' => 'Arial', 'color' => '#000000', ) ), array( 'width' => 500, 'height' => 38, 'fillColor' => 'none', 'textWrap' => 'square', 'rawWordML' => true ) ); // Header: finalise $header = new \Phpdocx\Elements\WordFragment($docx,'defaultHeader'); $header->addWordML($fgmt_bg_image); $header->addWordML($fgmt_text_box); $docx->addHeader(array('default'=>$header)); // Add some content to the document body $docx->embedHTML("

Hello world! The date and time is now: ".date('d/m/Y H:i:s')."."); // Create and download the dcx file $docx->createDocxAndDownload('test03');