I am using
org.docx4j.convert.in.xhtml.XHTMLImporterImpl
And when I call convert(html, ""); with following html:
<ul>
<li>first list item</li>
<li>
<table style="margin-left: auto; margin-right: auto; width: 75%; table-layout: fixed;">
<tbody>
<tr>
<td>
<p>ROW</p>
</td>
</tr>
</tbody>
</table>
</li>
</ul>
I get the following stack trace:
java.lang.ClassCastException: class org.docx4j.org.xhtmlrenderer.css.constants.IdentValue cannot be cast to class org.docx4j.org.xhtmlrenderer.css.style.derived.LengthValue (org.docx4j.org.xhtmlrenderer.css.constants.IdentValue and org.docx4j.org.xhtmlrenderer.css.style.derived.LengthValue are in unnamed module of loader 'app')
at org.docx4j.convert.in.xhtml.ListHelper.getAbsoluteIndent(ListHelper.java:381)
at org.docx4j.convert.in.xhtml.TableHelper.setupTblPr(TableHelper.java:120)
at org.docx4j.convert.in.xhtml.XHTMLImporterImpl.traverse(XHTMLImporterImpl.java:1020)
at org.docx4j.convert.in.xhtml.XHTMLImporterImpl.traverse(XHTMLImporterImpl.java:1284)
at org.docx4j.convert.in.xhtml.XHTMLImporterImpl.traverse(XHTMLImporterImpl.java:1284)
at org.docx4j.convert.in.xhtml.XHTMLImporterImpl.traverse(XHTMLImporterImpl.java:1284)
at org.docx4j.convert.in.xhtml.XHTMLImporterImpl.traverse(XHTMLImporterImpl.java:1284)
at org.docx4j.convert.in.xhtml.XHTMLImporterImpl.traverse(XHTMLImporterImpl.java:825)
at org.docx4j.convert.in.xhtml.XHTMLImporterImpl.convert(XHTMLImporterImpl.java:698)
I can tell that it is caused by margin-left and margin-right in the style attribute for the table because if I remove those convert() doesn't thrown an exception. Does anyone know any workaround for this that doesn't involve removing margins from the table?
margin-left is usually a length, but because of the value "auto", here it is an IdentValue.
https://github.com/plutext/docx4j-ImportXHTML/commit/466d2d01983333c3c4e456aea926f99bb4755016 ignores it if it is an IdentValue.