On an Android, I want to programmatically create a word document (which will contain images) with UTF-8 support.
Actually I am looking for a standard lightweight library.
Here is the complete way to open . doc file in Android 7.0 or less: Step-1: First of all, place your pdf file in assets folder like the following screenshot. Step-3: Now add a new java file which should extend from FileProvider Like in my case file name is LegacyCompatFileProvider and code inside of it.
Select the folder where you want to save your document. The dialog box will open > Select "Save as" > In the "Save as type" menu > Select the option "Word document (. docx)" > Click on the "Save as" button and a copy of your file will be saved in Docx format.
You have only a few options available:
Your best bet is on Aspose.Words for what you are looking for, but it comes with a price. Other two options are free and open source.
I can't Find Any Library To Work With Word Documents
I used Itext For Creating PDF files instead of Word Documents
This question is quite old, but as I had the same problem and was looking for a solution for a long time, I would like to point out these two free options:
https://github.com/centic9/poi-on-android
This enables you to create a custom Apache POI .jar-file with only the necessary parts of POI for your task, as POI is capable of handling other document types as well.
To enable word support with image handling for the custom jar, you would have to remove the following lines from the build.gradle file in the poishadow folder:
exclude 'org/apache/poi/wp/**'
exclude 'org/apache/poi/xwpf/**'
exclude 'org/openxmlformats/schemas/drawingml/**'
exclude 'org/openxmlformats/schemas/wordprocessingml/**'
Then build the project according to the documentation mentioned in the README of the project. This is necessary because the standard POI would not run on Android out of the box because of some not supported dependencies (javax etc.) and number of methods limit.
An alternative would be https://github.com/leonardoanalista/java2word which is also not optimized for Android, but has almost no dependencies and can be made to run on Android. It is only capable of creating .doc-files, but it is very easy to work with and to customize (A little bit of effort is necessary to support images on Android, to base64-encode them in the Android way.) This solution has some limitations when it comes to files with lots of images, as the files get quite big.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With