plutext / docx4j-ImportXHTML

Converts XHTML to OpenXML WordML (docx) using docx4j
136 stars 126 forks source link

Android/Gradle StyleDefinitionsPart.getCss()' on a null object reference #70

Open gilshallem opened 3 years ago

gilshallem commented 3 years ago

Hi I'm trying to convert html to docx on android

My dependencies definition (.gradle):

implementation 'javax.xml.bind:jaxb-api:2.3.1'
implementation 'javax.xml.stream:stax-api:1.0-2'
implementation 'com.fasterxml:aalto-xml:1.2.2'
implementation('org.docx4j:docx4j-ImportXHTML:8.0.0'){
    exclude module: 'commons-io'
}

Code:

WordprocessingMLPackage docxOut = WordprocessingMLPackage.createPackage();
XHTMLImporterImpl XHTMLImporter = new XHTMLImporterImpl(docxOut);
htmlString = "<html><head><title></title></head><body>hi</body></html>";
docxOut.getMainDocumentPart().getContent().addAll(
XHTMLImporter.convert(htmlString, null) );

Error:

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart.getCss()' on a null object reference
        at org.docx4j.convert.in.xhtml.XHTMLImporterImpl.stylesToCSS(XHTMLImporterImpl.java:460)
        at org.docx4j.convert.in.xhtml.XHTMLImporterImpl.getRenderer(XHTMLImporterImpl.java:271)
        at org.docx4j.convert.in.xhtml.XHTMLImporterImpl.convert(XHTMLImporterImpl.java:663)

PLEASE HELP :)

plutext commented 3 years ago

Can't reproduce in Java env with either ImportXHTML:8.0.0 or ImportXHTML:8.2.0