shafi
shafi

Reputation: 310

How to align text and image side by side in 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 ?

Upvotes: 4

Views: 8034

Answers (2)

Progi1984
Progi1984

Reputation: 498

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

Upvotes: 8

ohm
ohm

Reputation: 140

Please use this article , its does not support byt default so you can use this tutorial to create image like functionality http://www.shotdev.com/php/php-com-word/php-word-add-insert-picture-addpicture/

Upvotes: 0

Related Questions