Demo Aspose.Words for Android problem

Hello. I have a problem with demo examples of Aspose.Words for Android found at https://github.com/aspose-words/Aspose.Words-for-Java.

I extracted DocumentViewer example application, add to libs folder aspose-words-1.11-android-jdk15.jar. Then I try to start application, but when I choice *.docx file I got an error.

My configuration:

Android 4.2.2
ADT 23.0.2.1259578
Java 1.5
Android SDK Build-tools 20
08-12 17:32:33.530: E/AndroidRuntime(21144): FATAL EXCEPTION: Thread-413
08-12 17:32:33.530: E/AndroidRuntime(21144): java.lang.NoClassDefFoundError: asposewobfuscated.zz86
08-12 17:32:33.530: E/AndroidRuntime(21144): at com.aspose.words.FontInfoCollection.clear(Unknown Source)
08-12 17:32:33.530: E/AndroidRuntime(21144): at com.aspose.words.FontInfoCollection.(Unknown Source)
08-12 17:32:33.530: E/AndroidRuntime(21144): at com.aspose.words.DocumentBase.(Unknown Source)
08-12 17:32:33.530: E/AndroidRuntime(21144): at com.aspose.words.Document.(Unknown Source)
08-12 17:32:33.530: E/AndroidRuntime(21144): at com.aspose.words.Document.(Unknown Source)
08-12 17:32:33.530: E/AndroidRuntime(21144): at com.aspose.words.Document.(Unknown Source)
08-12 17:32:33.530: E/AndroidRuntime(21144): at com.aspose.words.android.AsposeWordsViewerActivity$1.run(AsposeWordsViewerActivity.java:80)
08-12 17:32:34.170: D/dalvikvm(21144): GC_CONCURRENT freed 564K, 19% free 6455K/7943K, paused 12ms+3ms, total 30ms
08-12 17:32:34.210: E/WindowManager(21144): Activity com.aspose.words.android.AsposeWordsViewerActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@42443680 that was originally added here
08-12 17:32:34.210: E/WindowManager(21144): android.view.WindowLeaked: Activity com.aspose.words.android.AsposeWordsViewerActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@42443680 that was originally added here
08-12 17:32:34.210: E/WindowManager(21144): at android.view.ViewRootImpl.(ViewRootImpl.java:383)
08-12 17:32:34.210: E/WindowManager(21144): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:292)
08-12 17:32:34.210: E/WindowManager(21144): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
08-12 17:32:34.210: E/WindowManager(21144): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
08-12 17:32:34.210: E/WindowManager(21144): at android.view.Window$LocalWindowManager.addView(Window.java:547)
08-12 17:32:34.210: E/WindowManager(21144): at android.app.Dialog.show(Dialog.java:277)
08-12 17:32:34.210: E/WindowManager(21144): at android.app.ProgressDialog.show(ProgressDialog.java:116)
08-12 17:32:34.210: E/WindowManager(21144): at com.aspose.words.android.AsposeWordsViewerActivity.convertDocument(AsposeWordsViewerActivity.java:72)
08-12 17:32:34.210: E/WindowManager(21144): at com.aspose.words.android.AsposeWordsViewerActivity.onActivityResult(AsposeWordsViewerActivity.java:64)
08-12 17:32:34.210: E/WindowManager(21144): at android.app.Activity.dispatchActivityResult(Activity.java:5192)
08-12 17:32:34.210: E/WindowManager(21144): at android.app.ActivityThread.deliverResults(ActivityThread.java:3137)
08-12 17:32:34.210: E/WindowManager(21144): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3184)
08-12 17:32:34.210: E/WindowManager(21144): at android.app.ActivityThread.access$1100(ActivityThread.java:130)
08-12 17:32:34.210: E/WindowManager(21144): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1243)
08-12 17:32:34.210: E/WindowManager(21144): at android.os.Handler.dispatchMessage(Handler.java:99)
08-12 17:32:34.210: E/WindowManager(21144): at android.os.Looper.loop(Looper.java:137)
08-12 17:32:34.210: E/WindowManager(21144): at android.app.ActivityThread.main(ActivityThread.java:4745)
08-12 17:32:34.210: E/WindowManager(21144): at java.lang.reflect.Method.invokeNative(Native Method)
08-12 17:32:34.210: E/WindowManager(21144): at java.lang.reflect.Method.invoke(Method.java:511)
08-12 17:32:34.210: E/WindowManager(21144): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:810)
08-12 17:32:34.210: E/WindowManager(21144): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:577)
08-12 17:32:34.210: E/WindowManager(21144): at dalvik.system.NativeStart.main(Native Method)

Could you help me with right direction to solve the problem?

Hi Oleg,

Thanks for your inquiry. I suggest you please increase the heap size of Eclipse and Android virtual device.

Moreover, please read system requirements of Aspose.Words for Android from here:
https://docs.aspose.com/words/java/system-requirements/

If
you still face problem, please attach your input Word document here for
testing. I will
investigate the issue on my side and provide you more information.

Hi Oleg,

Thanks for your inquiry. We have now divided the library into following two archives:

  • aspose-words-1.11-android-jdk15.jar: The first one includes public API and its auxiliary methods.
  • aspose-words-1.11-libs-android-jdk15.apk: The second one includes third party jars, basic classes and resources.

To include Aspose.Words for Android into the project you should place “aspose-words-1.11-android-jdk15.jar” in the folder “libs” of your project, and the archive “aspose-words-1.11-libs-android-jdk15.apk” into the folder “assets”. After that you need to indicate in “AndroidManifest.xml” file that you are going to use AsposeWords application as the basic one. Please see the following markup:

…
…
<application 
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:name="com.aspose.words.AsposeWordsApplication"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
…
…

I hope, this helps.

Best regards,

Hi Awais.

Your advice work for me, demo app works. Thanks!

But there are some questions about how it works.

  1. Can Aspose.Word directly render Word files, or only through converting?

Because converting simple word file to PNG takes few minutes

Hi Oleg,

Thanks for your inquiry. Yes, rendering to fixed page formats such as PDF, XPS, Images etc is a bit slower than simply converting to flow formats such as DOCX, DOC, RTF etc. I think, you can render a document directly to Image formats by using the code from the following link:

https://docs.aspose.com/words/java/rendering/

I hope, this helps.

Best regards,

I want to open .doc file , how its possible?

is there any sample ?

Hi Amar,

Thanks for your inquiry. Please note that Aspose.Words for Android is a class library and with it you can programmatically generate, modify, convert and render word processing documents. So, it does not offer any UI or control for performing these document processing tasks. However, if your’re intended to just preview your Word document in your android application, I can offer you a simple way that will help you in achieving what you are looking for.

  1. Load your Word document into Aspose.Words for Android
  2. Generate images against each page in Word document and then view them in some android control.

Please see the following code that uses standard ImageView widget to show Aspose.Words generated images:

try
{
    String licString = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Aspose.Words.Android.lic";
    String inputPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/input.docx";
    String outputPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/";
    com.aspose.words.License lic = new com.aspose.words.License();
    lic.setLicense(licString, this);
    com.aspose.words.Document doc = new com.aspose.words.Document(inputPath);
    com.aspose.words.ImageSaveOptions options = new com.aspose.words.ImageSaveOptions(SaveFormat.PNG);
    options.setPageCount(1);
    for (int i = 0;
    i < doc.getPageCount();
    i++)
    {
        options.setPageIndex(i);
        doc.save(outputPath + "out_" + i + ".png", options);
    }
    Bitmap bm = BitmapFactory.decodeFile(outputPath + "out_1.png");
    ImageView img = (ImageView)findViewById(R.id.imageView1);
    img.setImageBitmap(bm);
}
catch (Exception e)
{
    e.printStackTrace();
}

I hope, this helps.

Best regards,

A post was split to a new topic: How to Create Word Document Editor in Android App