1

This is particularly a new question on stackoverflow. I want to know how to make file conversions on android using Jodconverter library. I see a lot of examples and questions but all are based on java and not answering android specific questions not even the official website. Though I did see the owner himself has used the library in one android app he released so its possible to make conversions on android with JODconverter.

The code is below from official site with android version:

OfficeManager officeManager = new DefaultOfficeManagerConfiguration().buildOfficeManager();   
    officeManager.start();   
    OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager);   
    try{  
        converter.convert(new File("/sdcard/tsxt.doc"), new File("/sdcard/tsx465t.docx"));   

    }catch(Exception e){  
        e.printStackTrace();  
    }  
    officeManager.stop(); 

Logcat output of crash I get at run time on including all libraries except unoil library (because adding unoil gives me Conversion to Dalvik failed error):

06-28 05:28:50.086: E/AndroidRuntime(28629): FATAL EXCEPTION: main
06-28 05:28:50.086: E/AndroidRuntime(28629): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jopendocs/com.example.jopendocs.JODActivity}: java.lang.IllegalStateException: officeHome not set and could not be auto-detected
06-28 05:28:50.086: E/AndroidRuntime(28629):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2246)
06-28 05:28:50.086: E/AndroidRuntime(28629):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2296)
06-28 05:28:50.086: E/AndroidRuntime(28629):    at android.app.ActivityThread.access$700(ActivityThread.java:151)
06-28 05:28:50.086: E/AndroidRuntime(28629):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
06-28 05:28:50.086: E/AndroidRuntime(28629):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-28 05:28:50.086: E/AndroidRuntime(28629):    at android.os.Looper.loop(Looper.java:137)
06-28 05:28:50.086: E/AndroidRuntime(28629):    at android.app.ActivityThread.main(ActivityThread.java:5293)
06-28 05:28:50.086: E/AndroidRuntime(28629):    at java.lang.reflect.Method.invokeNative(Native Method)
06-28 05:28:50.086: E/AndroidRuntime(28629):    at java.lang.reflect.Method.invoke(Method.java:511)
06-28 05:28:50.086: E/AndroidRuntime(28629):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
06-28 05:28:50.086: E/AndroidRuntime(28629):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
06-28 05:28:50.086: E/AndroidRuntime(28629):    at dalvik.system.NativeStart.main(Native Method)
06-28 05:28:50.086: E/AndroidRuntime(28629): Caused by: java.lang.IllegalStateException: officeHome not set and could not be auto-detected
06-28 05:28:50.086: E/AndroidRuntime(28629):    at org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration.buildOfficeManager(DefaultOfficeManagerConfiguration.java:163)
06-28 05:28:50.086: E/AndroidRuntime(28629):    at com.example.jopendocs.JODActivity.onCreate(JODActivity.java:22)
06-28 05:28:50.086: E/AndroidRuntime(28629):    at android.app.Activity.performCreate(Activity.java:5250)
06-28 05:28:50.086: E/AndroidRuntime(28629):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
06-28 05:28:50.086: E/AndroidRuntime(28629):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2210)
06-28 05:28:50.086: E/AndroidRuntime(28629):    ... 11 more
Abhishek Singh
  • 415
  • 1
  • 12
  • 24

2 Answers2

2

I think this couldn't be possibly as JODConverter needs a valid OpenOffice installation. While starting, this library tries to guess OpenOffice installation folder (most of the times, according to the Operating System, OpenOffice is located to a specific folder), but under Android, I am not sure this is possibly. I don't have an Android device, I don't know if OpenOffice is available on this OS. If it is, you have to set up the officeHome attribut (look at a org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration class if I am right)

LouMéou
  • 31
  • 6
0

The code from the official website is different from yours:

final LocalOfficeManager officeManager = LocalOfficeManager.install(); 
try {

    // Start an office process and connect to the started instance (on port 2002).
    officeManager.start();

    // Convert
    JodConverter
             .convert(inputFile)
             .to(outputFile)
             .execute();
} finally {
    // Stop the office process
    OfficeUtils.stopQuietly(officeManager);
}     
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Yuntai
  • 1
  • 1
  • Since `artofsolving` can be seen in the stacktrace, we can assume that the version of JODConverter we are talking about is not the one used in the example you posted. But like @LouMéou said, I'm not sure it is possible to use JODconverter on android, since it requires a (Libre or Open) Office installation. – sbraconnier Mar 19 '18 at 13:45