How to display word doc file in android using aspose word lib

I want to display word doc file, it should be from within app.

Is it possible to display word doc file using aspose word lib?

Hi Pratibha,

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, we 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();
}

Hope, this helps.

Best regards,

Thanks Awais,it really helpful for me.But when i integrate this code into my code then it will give me the following error.

Error:(97, 45) error: cannot access zzF4
class file for asposewobfuscated.zzF4 not found
Error:Execution failed for task ‘:app:compileDebugJavaWithJavac’.
\> Compilation failed; see the compiler error output for details.

I have attached my MainActivity.java file here for reference.

Hi Pratibha,

Thanks for your inquiry. Please download this Android Studio test project. After that please do the following steps to generate .jar from .apk:

  1. Extract attached “dex2jar.zip” to "“C:\dex2jar”
  2. Go to “~\HelloWorld\app\src\main\assets” folder in “HelloWorld” project and copy “aspose-words-1.12-libs-android-jdk16.apk” to “C:\dex2jar” folder
  3. Open “aspose-words-1.12-libs-android-jdk16.apk” with WinRar and extract “classes.dex” file to “C:\dex2jar”
  4. Open command prompt in Windows and enter the following commands
  5. C:\WINDOWS\system32>cd/
  6. C:>cd dex2jar
  7. C:\dex2jar>d2j-dex2jar.bat c:\dex2jar\classes.dex
  8. dex2jar c:\dex2jar\classes.dex -> .\classes-dex2jar.jar
  9. C:\dex2jar>
  10. Now we have “classes-dex2jar.jar” which contains all the obfuscated classes
  11. Copy this .jar to “~\HelloWorld\app\libs” folder of “HelloWorld” project
  12. Now in Android Studio go to “Project Structure” of “HelloWorld” project
  13. Under “Modules”, select “app” and go to “Dependencies” tab
  14. Click ‘+’ and add a file dependency for “~\HelloWorld\app\libs\classes-dex2jar.jar”
  15. Under “Scope” column choose “Provided” value for this .jar and click OK and “Rebuild Project”.

Hope, this helps.

Best regards,

Thanks Awais for this solution , i have follow all this step one by one and run the program but i have cought one error,

2 errors; aborting

Error:Execution failed for task ‘:app:preDexDebug’.
\> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command ‘/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java’’ finished with non-zero exit value 1

How to solved this error? It is really end towards to fix the problem, Could you please help on this.

Details error log:
:app:preDexDebug
EXCEPTION FROM SIMULATION:
expected type int[] but found float[]
…at bytecode offset 00000062
locals[0000]: Lasposewobfuscated/zzW9;
locals[0001]: 
locals[0002]: 
locals[0003]: 
locals[0004]: 
locals[0005]: I
locals[0006]: 
locals[0007]: I
locals[0008]: [F
locals[0009]: [F
locals[000a]: [[F
…while working on block 005f
…while working on method zzZ:(Lasposewobfuscated/zzW9;)Lasposewobfuscated/zzU;
…while processing zzZ (Lasposewobfuscated/zzW9;)Lasposewobfuscated/zzU;
…while processing asposewobfuscated/zzU.class
1 error; aborting
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ‘:app:preDexDebug’.
\> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
\AppData\Local\Android\Sdk\build-tools\20.0.0\dx.bat --dex --output \programs\Document_Viewer_and_Converter_for_Android-master\app\build\intermediates\pre-dexed\debug\classes-dex2jar-b72a6dcf664bc63ed3b3a2ed983299027c38cf54.jar 
\programs\Document_Viewer_and_Converter_for_Android-master\app\libs<b style="background-color: rgb(255, 255, 0);">classes-dex2jar.jar
Error Code:
1
Output:
EXCEPTION FROM SIMULATION:
expected type int[] but found float[]
…at bytecode offset 00000062
locals[0000]: Lasposewobfuscated/zzW9;
locals[0001]: 
locals[0002]: 
locals[0003]: 
locals[0004]: 
locals[0005]: I
locals[0006]: 
locals[0007]: I
locals[0008]: [F
locals[0009]: [F
locals[000a]: [[F
…while working on block 005f
…while working on method zzZ:(Lasposewobfuscated/zzW9;)Lasposewobfuscated/zzU;
…while processing zzZ (Lasposewobfuscated/zzW9;)Lasposewobfuscated/zzU;
…while processing asposewobfuscated/zzU.class
1 error; aborting

* Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 1 mins 14.398 secs

Hi Pratibha,

Thanks for your inquiry. Sorry, I forgot to attach “dex2jar.zip” with my previous post. I have attached it now here, please repeat the steps from my previous post. Hope, this helps.

Best regards,

Thanks Awais for patiently providing your valuable help, i have follow all this steps one by one.

The project build successfully but while launching it fails. Following is the error log:

It gives error like:

(
EXCEPTION FROM SIMULATION:
expected type int[] but found float[]
from zzu.class
)
Information:Gradle tasks [:app:assembleDebug]
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72310Library UP-TO-DATE
:app:prepareComAndroidSupportDesign2310Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72310Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42310Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources UP-TO-DATE
:app:preDexDebug
Uncaught translation error: com.android.dx.cf.code.SimException: expected type int[] but found float[]
Uncaught translation error: com.android.dx.cf.code.SimException: expected type int[] but found float[]
2 errors; aborting
**Error:Execution failed for task ‘:app:preDexDebug’.
\> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command ‘/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java’’ finished with non-zero exit value 1**
Information:BUILD FAILED
Information:Total time: 31.258 secs
Information:1 error
Information:0 warnings
Information:See complete output in console

When i extracting that classes-dex2jar.jar file than through JD-GUI i open that file it contains one folder,i have attached that screen shot here:

asposewobfuscated

Hi Pratibha,

Thanks for the additional information. What IDE are you using for Android development? Please zip and attach your simple project causing this problem here for testing.

Best regards,

Thanks Awais, I’m using Android studio.
I have attached zip file of my project.

Hi Pratibha,

Thanks for your inquiry. We are working over your query and will get back to you soon.

Best regards,

Hi Awais,actually i’m developing one small application and i’m still stuck with above mention problem.
So,is there is any solution for this above mention problem?

Hi Pratibha,

Thanks for being patient. To make this process simple, we will rebuild Aspose.Words for Android’s distribution package and consider shipping Aspose.Words for Android library the same way Google supplies its libraries (e.g. in .aar format). Your thread has been linked to the appropriate issue (WORDSANDROID-194) and you will be notified as soon as this issue is resolved. Sorry for the inconvenience.

Best regards,

Thanks Awais.

Your reply will really helpful for me.

Hello,

Have you any news for us?

Best regards,

Hi Pratibha,

Thanks for being patient. This issue is currently pending for analysis and is in the queue. Unfortunately, at the moment we cannot provide you any reliable estimate as to when new version will be released. However, you will surely be notified as soon as it is resolved. Sorry for inconvenience.

Best regards,

The issues you have found earlier (filed as WORDSANDROID-194) have been fixed in this Aspose.Words for Android 17.2.0 update.