docx4j html to docx android

779 views Asked by At

I have already checked the DocxtoHTML for android project of docx4j on github and continuing the same code, I am trying to convert the html back to docx. Following is my code for the same. I have referred DocxToXhtmlAndBack.java for writing my code. Since the code is for Java but I am trying to implement it on android I am encountering crash and error like Unable to execute dex:Multiple dex files define Lorg/docx4j/convert/in/xhtml/ListHelper;. Therefore I also checked ConvertInXHTMLDocument.java of the same project with hope to convert html file saved in internal storage to docx but I couldn't write android version of the same. Please guide me and help me write conversion code from html to docx using Docx4j library. I would not mind using same html displayed in AndroidDocxtoHTML github project as well.

My android version of code for conversion of html to docx in continuation to DocxtoHTML Docx4j Github project Activity.

Code:

        String stringFromFile = FileUtils.readFileToString(new File(Environment.getExternalStorageDirectory().getAbsoluteFile()+File.separator+"simple"), "UTF-8");


        WordprocessingMLPackage docxOut = WordprocessingMLPackage.createPackage();
        NumberingDefinitionsPart ndp = new NumberingDefinitionsPart();
        docxOut.getMainDocumentPart().addTargetPart(ndp);
        ndp.unmarshalDefaultNumbering();    

        XHTMLImporterImpl XHTMLImporter = new XHTMLImporterImpl(docxOut);
        XHTMLImporter.setHyperlinkStyle("Hyperlink");

        docxOut.getMainDocumentPart().getContent().addAll( 
                XHTMLImporter.convert(stringFromFile, null) );

        docxOut.save(new File(Environment.getExternalStorageDirectory().getAbsoluteFile()+File.separator + "DocxToXhtmlAndBack.docx") );

Please correct me as I am wrong somewhere. I would like to inform I have tried all questions on stackoverflow but nothing is down to code and more helpful for android.

I must also add that I am getting the error Unable to execute dex:Multiple dex files define Lorg/docx4j/convert/in/xhtml/ListHelper; only after I added docx4jimportXHTML library into the project without which the conversion is not possible.

UPDATE: I also came to know that with docx4jimportXHTML.jar we can convert docx to xhtml and back to docx but the code at AndroidDocxToHtmlActivity.java (link mentioned above) is for JAVA. Can anyone tell me how to write an android equivalent for same.

0

There are 0 answers