Forum


Replies: 3   Views: 29
Setting td widths using embedhtml

Posted by matteo.moretti  · 24-04-2025 - 10:07

After upgrading from v14.5 to v16 I noticed a braking change in the behavior of embedHTML function.
This is my code snippet:

$document = new CreateDocx();
$documento->embedHTML($html, [
    'parseDivsAsPs' => true,
    'downloadImages' => true, 
]);

The HTML I'm using for testing is the following

<div>
<table style="border-collapse: collapse; width: 100%; height: 90px;" border="1">
<tbody>
<tr style="height: 18px;">
<td style="width: 14.8275%; height: 18px;">aaaaa</td>
<td style="width: 18.5059%; height: 18px;">&nbsp;</td>
<td style="width: 20.4814%; height: 18px;">&nbsp;</td>
<td>&nbsp;</td>
<td style="width: 20.8901%; height: 18px;">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr style="height: 18px;">
<td style="width: 14.8275%; height: 18px;">&nbsp;</td>
<td style="width: 18.5059%; height: 18px;">&nbsp;</td>
<td style="width: 20.4814%; height: 18px;" rowspan="3">ccccccc</td>
<td>&nbsp;</td>
<td style="width: 20.8901%; height: 18px;">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr style="height: 18px;">
<td style="width: 14.8275%; height: 18px;">&nbsp;</td>
<td style="width: 18.5059%; height: 18px;">&nbsp;</td>
<td>&nbsp;</td>
<td style="width: 20.8901%; height: 18px;">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr style="height: 18px;">
<td style="width: 14.8275%; height: 18px;">&nbsp;</td>
<td style="width: 18.5059%; height: 18px;">&nbsp;</td>
<td>&nbsp;</td>
<td style="width: 20.8901%; height: 18px;">dcdscds</td>
<td>&nbsp;</td>
</tr>
<tr style="height: 18px;">
<td style="width: 14.8275%; height: 18px;">&nbsp;</td>
<td style="width: 18.5059%; height: 18px;">&nbsp;</td>
<td style="width: 20.4814%; height: 18px;">&nbsp;</td>
<td>&nbsp;</td>
<td style="width: 20.8901%; height: 18px;">&nbsp;</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
</div>

Before the upgrade the output was a 6 columns layout now I only have 4 columns (<td> elements without an explicit width are being removed!).
How can I get back to the previous behavior?