views:

31

answers:

1

Hi. In my web-application i'm using phplivedocx for text changing. But i also need to dynamically change images in my docx template. What tool do you recommend?

Thanks in advance.

A: 

Found the solution.

quote from phplivedocx forum: "I found a way to insert dynamic image in docx template before sending it to LiveDocx (so it don't work with hosted templates).

That's the way I do it (in Php): - First I put a default image in my local word template - Before generating the PDF, considere the docx as if it was a zip archive (you can extract manually to confirm it), so: - In this archive replace the file /word/media/image1.png by the dynamic image (flat png formated, don't know about format limitations) - Close the archive.

At this step, if you open the docx template in word, you'll be able to see the dynamic image replacing the default image.

After that, you can process the request to liveDocx.

There's some limitations in this method and I hope Boilerplate mecanism will come soon to do it a better way, but in my case it just work like I want. "

Here is the code how to change image in docx template in php:

$zip = new ZipArchive;
$zip->open('documents/template_tm.docx');
$zip->addFile('new_image.png', 'word/media/image1.png');
$zip->close();
dsplatonov