Forum


Replies: 4   Views: 4268
Lib crashes when i try to replace several image placeholder in header
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 jdespatis  · 15-07-2014 - 10:10

I have a template with 2 placeholders in the header ($HEADERIMG$ and $LOGO$) and I use the following test code: $docx = new \CreateDocxFromTemplate("replacePlaceholderImages.docx"); $docx->replacePlaceholderImage('HEADERIMG', 'images/user.png', array("target" => "header")); $docx->replacePlaceholderImage('LOGO', 'images/qrcode.png', array("target" => "header")); $docx->createDocx('/tmp/example_replacePlaceholderImages_1'); And i get the PHP error: ContextErrorException: Warning: DOMDocument::loadXML(): Empty string supplied as input in [...]/phpdocx/classes/CreateDocxFromTemplate.inc line 1096 (indeed, after first replacing HEADERIMG placeholder, the lib seems to clean the LOGO placeholder in the same time, from pov) => bug in library or I'm badly using the lib ? Thanks for your feedback

Posted by jdespatis  · 15-07-2014 - 10:36

Here is a screenshot of the template used: http://screencast.com/t/mBbQNqRSuY It's in fact the template tuned a little from: http://www.phpdocx.com/api-documentation/templates/replace-placeholder-image-Word-document

Posted by admin  · 15-07-2014 - 15:02

Hello, You can't duplicate the same image, because Word doesn't add two images but only one. You need to use two different files or use the method replaceVariableByWordFragment with text placeholders. Regards.

Posted by jdespatis  · 15-07-2014 - 15:52

Ok, so I've done a new try: I've created a new template from scratch, with 2 different images as placeholders ($logo$ and $qrcode$) in the header (here is my template rendered: http://screencast.com/t/gyZgkIEHY2y, I can send it to you, no problem) And then I replace those 2 placeholders with 2 different images (indeed, all those 4 images are all different), thanks to the code: $docx = new \CreateDocxFromTemplate("TestTemplate2.docx"); $docx->replacePlaceholderImage('logo', 'images/user.png', array("target" => "header")); $docx->replacePlaceholderImage('qrcode', 'images/event.jpg', array("target" => "header")); $docx->createDocx('/tmp/example_replacePlaceholderImages_1'); But I get the same exception (and the resulting docx is not generated): ContextErrorException: Warning: DOMDocument::loadXML(): Empty string supplied as input in [...]/phpdocx/classes/CreateDocxFromTemplate.inc line 1096 Any idea ?

Posted by admin  · 15-07-2014 - 16:32

Hello, Please send the questions to contact@phpdocx.com to get the support. Regards.