Forum


Replies: 6   Views: 4385
Add embed html image to header not working
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 ytalexx888  · 09-10-2015 - 20:49

Hi

 

I am attempting to add an image to a header formatted in a table with some text.  The image is to be on the right side, right justified and the text is to be on the left side, left justified.

Everything works except when I add an image.

I have tried to add an embeddedHTML table and I have tried to the addTable method.  Both methods throw an error, by either not displaying the image or claiming that the documents contents are corrupted.

Adding the same image to the body of the document is no problem.

Here are both codes:

EmbedHTML:

$header = new WordFragment($docx, 'defaultHeader');

$hTableValues = "<table><tr><td width=500><span style='font-size: 14pt; font-weight: bold'>".$CASp_number."</span><br /><span style='font-size: 10pt'>".$meta['Name']."<br />".$meta['Description']."</span></td><td align='right' width=500>".$logo."</td></tr></table>";

$header->embedHTML($hTableValues, array('spacingBottom' => 400));

$docx->addHeader(array('default' => $header));

 

The above method yields "Microsoft Office cannot open this file because some parts are missing or invalid" but no errors are logged.

 

addTable:

$header = new WordFragment($docx, 'defaultHeader');

$leftFragment = new WordFragment($docx);

$headerLeft = array();

$headerLeft[] = array('text' => $CASp_number, 'jc' => 'left', 'sz' => 14, 'b' => 'on', 'lineBreak' => 'after', 'lineSpacing' => 120);

$headerLeft[] = array('text' => $meta['Name'], 'jc' => 'left', 'sz' => 10, 'b' => 'on', 'lineBreak' => 'after', 'lineSpacing' => 120);

$headerLeft[] = array('text' => $meta['Description'], 'jc' => 'left', 'sz' => 10, 'b' => 'off');

$leftFragment->addText($headerLeft);
    

$rightFragment = new WordFragment($docx);

$headerImage = array('src' => 'logos/logo-'.$accountDBNUM[0].'.png');

$rightFragment->addImage($headerImage);

    

$tArray = array(array($leftFragment, $rightFragment));

$header->addTable($tArray, array(), array());

$docx->addHeader(array('default' => $header));

 

Using this second method generates the following error: PHP Fatal error:  Call to a member function addFile() on a non-object in /home/adaverac/public_html/phpdocx4/classes/CreateDocx.inc on line 2082

 

I can't seem to figure this problem out, as adding the image to the document yields no problems.  The header generates properly with either method when the image is left out.

 

I don't care which method I use, as long as I am able to get the necessary results.  Any suggestions or thoughts you have would be much appreciated.  Thank you.