Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to align text and image side by side in phpWord?

Tags:

php

phpword

I need to align a logo and text side by side. But when generating the word document, the text always comes beneath the logo image.I tried the solution pointed out here: http://phpword.codeplex.com/discussions/232684

But it didn't work for me. Here's what i tried (not the solution mentioned above)

$section = $PHPWord->createSection();
$image = $section->addImage('_mars.jpg',array ('width'=>100));
// Add table
$table = $section->addTable(); 
for($r = 1; $r <= 1; $r++) { // Loop through rows
    // Add row
    $table->addRow();
    for($c = 1; $c <= 1; $c++) { // Loop through cells
      // Add Cell
     //I tried adding image in this line.
     $table->addCell(1750)->addText("Row $r,Cell ".
$section->addImage('_mars.jpg',array('width'=>100)));
    }
}

and I'm getting this error in

$section->addImage() partCatchable fatal error: Object of class PHPWord_Section_Image could not be converted to string in 

Can anyone tell me how I can add image in table cell ?

like image 993
shafi Avatar asked Mar 21 '23 21:03

shafi


1 Answers

You should use text run :

$section = $PHPWord->createSection();
$image = $section->addImage('_mars.jpg',array ('width'=>100));
// Add table
$table = $section->addTable(); 
for($r = 1; $r <= 1; $r++) { // Loop through rows
    // Add row
    $table->addRow();
    for($c = 1; $c <= 1; $c++) { // Loop through cells
        // Add Cell
        $cell = $table->addCell(1750);
        $textrun = $cell->createTextRun();
        $textrun->addText("Row $r,Cell ");
        $textrun->addImage('_mars.jpg',array('width'=>100));
    }
}

Link : TextRun

like image 84
Progi1984 Avatar answered Mar 31 '23 20:03

Progi1984