Search code examples
androidapache-poidocumentdocx4j

Need suggestions regarding the .doc file reading in android


I'll be working on a new app that reads the .doc and .docx files and get the number of words, no of lines, no of pages, no of images, no of formula's so so from the particular word document.

So, i used the Java Scanner class to get the word and line count from the word document, but i failed to get the page count and image count.

After that i found an API (Apache POI) which having the similar properties what i need to get.

Here is my question: The Apache POI (.docx not supported) is heavy weight jar. So is there any alternative to Jar's available to get the page numbers, no of images present in the word document?

Please suggest. Thanks in advance.


Solution

  • You can use a Scanner with a FileInputStream instead of BufferedReader with a FileReader. For example:-

    File file = new File("sample.txt");
    Scanner sc = new Scanner(new FileInputStream(file));
    int count=0;
    while(sc.hasNext()){
        sc.next();
        count++;
    }
    System.out.println("Number of words: " + count);
    

    Hope instead of using a heavy weight jar, this is a simple and easy solution for your case.