Forum


Replies: 3   Views: 191
Replacevariablebyhtml and img with a float
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 admin  · 05-02-2024 - 07:50

Hello,

We have done some tests with your code and in all cases the DOCX output is correct and no corrupted error appears when opening the DOCX with MS Word 2021, MS Word 2019, MS Word 2016, MS Word 2013, MS Word 2010, MS Word 2007, MS Word Online and LibreOffice 7.

After doing some more tests with an outdated version of MS Word 2007 (a very old version of MS Word 2007), we think we have been able to replicate your issue. With other MS Word 2007 revisions and any other MS Word versions these error don't appear. It only happens with some outdated old versions of MS Word 2007 when the float style is applied transforming HTML. It's a very strange error from the order of a specific tag.
Please do the following change in your version of phpdocx:

Edit HTML2WordML.php and go to the following line (around line 1676):

if (isset($properties['float']) && ($properties['float'] == 'left' || $properties['float'] == 'right')) {

In this if block, replace the following lines:

$this->wordML .= '<wp:extent cx="' . $cx . '" cy="' . $cy . '" /><wp:wrapSquare wrapText="bothSides" /><wp:docPr id="' . $docPr . '" name="' . $tempName . '" descr="' . rawurlencode($descr) . '">'.$docPrContent.'</wp:docPr>';
$this->wordML .= '<wp:effectExtent b="'.$distance['bottom'].'" l="'.$distance['left'].'" r="'.$distance['right'].'" t="'.$distance['top'].'"/>';

with:

$this->wordML .= '<wp:extent cx="' . $cx . '" cy="' . $cy . '" />';
$this->wordML .= '<wp:effectExtent b="'.$distance['bottom'].'" l="'.$distance['left'].'" r="'.$distance['right'].'" t="'.$distance['top'].'"/>';
$this->wordML .= '<wp:wrapSquare wrapText="bothSides" /><wp:docPr id="' . $docPr . '" name="' . $tempName . '" descr="' . rawurlencode($descr) . '">'.$docPrContent.'</wp:docPr>';

(as you can check, we have just moved wp:effectExtend after wp:extent).

After applying this minor change, please try again, it should be solved now with your MS Word 2007 version. This same change has been added to the current testing branch to be included in the stable release. We have done tests with all MS Word versions after applying this change and the DOCX is correct in all cases.

Regards.