Forum


Replies: 8   Views: 3530
Template crashed when replace templatevariable with image
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by medscope  · 29-11-2012 - 23:39

I got a existing .doc word document.

I converted it into .docx in order to use phpdocx, when I replace a template variable with image, the document just crashed,

Posted by admin  · 11-04-2013 - 12:13

Hello,

How did you converted DOC to DOCX?. Could you attach your DOCX to test it?

Regards.

Posted by medscope  · 11-04-2013 - 12:13

i just open the doc file in word and save it as word document (.docx).

how can i attach files?

Posted by admin  · 11-04-2013 - 12:13

Hello,

You can upload your document to any share service (like DropBox) and share your link or contact us (http://www.phpdocx.com/contact) and we'll reply you.

Regards.

Posted by medscope  · 11-04-2013 - 12:13


http://dl.dropbox.com/u/30871117/HMRReport_master.doc

plz, this is the original file that i used and converted to .docx

Posted by admin  · 11-04-2013 - 12:13

Hello,

I've been checking your DOC after exporting it to DOCX. The problem is that you're merging more than one placeholder and
string in the same cell. As using this method

$docx->addTemplateVariable('P_GName', 'image.png', 'image')

the image is replaced with an altchunk tag, Word is unable to read w:r tags that has an altchunk tag and more content.
So the solution it's to set a cell for each placeholder or use replaceTemplateVariableByHTML method that don't use altchunk but other WordML tags.

Regards.

Posted by medscope  · 11-04-2013 - 12:13

Hi,

I have tried merge image using,

$Logo="./UserLogos/MRM Banner-crop.gif";
$logo_HTML="<img src='".$Logo."'>";
$docx->replaceTemplateVariableByHTML('logo','inline',$logo_HTML);
and
$docx->replaceTemplateVariableByHTML('logo','block',$logo_HTML);

But the template variable is replace by nothing.

I'm sure the HTML is correct, because When I put a die($logo_HTML); I can see that image in the browser.
But in the resulting document, the template variable is replaced with blank.

Another thing is that, when we put everything in a blank new document save it as .docx. The image works fine.
No idea what's going on.

Posted by admin  · 11-04-2013 - 12:13

Hello,

The image must be readable by file_get_contents, so I recommend you to set an URL as image source.

Regards.