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

I need to align the logo and text side by side. But when creating a dictionary document, the text always appears under the logo. I tried the solution indicated here: http://phpword.codeplex.com/discussions/232684

But that did not work for me. Here is what I tried (solution not 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 get this error in

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

Can someone tell me how can I add an image to a table cell?

+4
source share
2 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

+6
source

All Articles