loadTemplate and addImage

Dec 13, 2011 at 10:24 AM

Is it possible to use the loadtemplate function and use addImage at the same time. Mine template is working great but when i use the addImage function the template isn't working any more. Is there some one who can help me......

$document = $PHPWord->loadTemplate('Template.docx');

$document->addImage('myimage.jpg');

Jul 11, 2012 at 11:38 AM

Did you know the solution?

that's my problem now :(

can you help me!?

Jul 25, 2012 at 5:40 AM

currently, the version can ONLY replace keywords into templates...but there is a trick: from your template, insert "blank" images where you want.

Then, load the template and make the replacements.

Then, save the docx generated from the template: open it with zlib, replace the imagexx.jpg

Nov 15, 2012 at 5:35 AM
Edited Nov 15, 2012 at 5:35 AM

Like kiminox said, it's not possible. Here it is a function that will replace the image. You must put it on PHPWord/Template.php.

 

public function replaceImage($path,$imageName){
        $this->_objZip->deleteName('word/media/'.$imageName);
        $this->_objZip->addFile($path,'word/media/'.$imageName);
    }

 

$path='path/to/your/image'

$imageName='imagexx.png'

to find out wich one is the image you want to replace, open the docx file with winrar or something similar and take a look a t word/media directory.