Page 1 of 1

Android HTML to docx error

PostPosted: Wed Jul 22, 2015 6:54 am
by dev7abhi
I am trying to convert html string to docx using the below code as per
https://github.com/plutext/docx4j-Impor ... dBack.java

I added the following libraries other than the ones used in Android docx to HTML by docx4j project on github:
1. docx4j-importXHTML-3.2.2.jar
2. itext-2.1.7.jar
3. xml-renderer-3.0.0.jar
4. xalan-2.7.0.jar

The following is the android version of code in XhtmlToDocxAndBack.java :
Code: Select all
try {
                    String html = "<html><head><title>Import me</title></head><body><p>Hello World!</p></body></html>";

                    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();

                    XHTMLImporterImpl XHTMLImporter = new XHTMLImporterImpl(wordMLPackage);
                    XHTMLImporter.setDivHandler(new DivToSdt());

                    wordMLPackage.getMainDocumentPart().getContent().addAll(XHTMLImporter.convert(html, null));

                    System.out.println(XmlUtils.marshaltoString(wordMLPackage
                            .getMainDocumentPart().getJaxbElement(), true, true));

                    wordMLPackage.save(new File("/sdcard/OUT_from_XHTML.docx"));


                } catch (Docx4JException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }


Error I receive:
Error:(166, 34) error: cannot access XHTMLImporter
class file for org.docx4j.convert.in.xhtml.XHTMLImporter not found

Error I receive if I comment out XHTMLImporter.setDivHandler(new DivToSdt()):
Error:(168, 34) error: cannot access XHTMLImporter
class file for org.docx4j.convert.in.xhtml.XHTMLImporter not found

Error I receive if I comment out wordMLPackage.getMainDocumentPart().getContent().addAll(XHTMLImporter.convert(html, null)); as well:
Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: org/docx4j/convert/in/xhtml/ListHelper.class

I should mention docx to html is working fine in Android studio but the above error is buggy. Please tell me how to fix it.
Thanks in advance.