Forum


Replies: 6   Views: 2257
Get the image size of an image placeholder when using createdocxfromtemplate
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 ISSL-blocked  · 19-06-2019 - 13:30

The only topic I can find related to this is https://www.phpdocx.com/en/forum/default/topic/1633 but the information there doesn't work.

I am loading a document using CreateDocxFromTemplate, and there is a placeholder image in there with a placeholder of $FLOORPLAN$. I need to do is get its width, because I can't just use replacePlaceholderImage as it will squash the image (the floor plans are different sizes), and I can't set the width as I don't know the width of the placeholder image (it changes between templates).

I thought this would work looking at Indexer.php, but it requires DOMDocument and I can't see a way to create that from CreateDocxFromTemplate.

// load XML content
$contentDOM = new DOMDocument();
$contentDOM->loadXML($xml); # How do I do this with CreateDocxFromTemplate??

// do a xpath query getting only image tags
$contentXpath = new DOMXPath($contentDOM);
$contentXpath->registerNamespace('rel', 'http://schemas.openxmlformats.org/package/2006/relationships');
$imageEntries = $contentXpath->query('//rel:Relationship[@Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"]');

How do I simply get the width of a placeholder image?