Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am new to rendering files in android, and I want to render or display a docx file in my application.

I had already extract text from docx file, but now I want to extract images from the docx file as well.

I've found several ways to display images in pure Java, but are there any good examples for Android?

I tried this code to fetch Images but not working...

public void extractImages(Document xmlDoc)
{
    NodeList binDataList = xmlDoc.getElementsByTagName("w:drawings");
    String fileName = "";
    Node currentNode;
    for(int i = 0; i < binDataList.getLength(); i++)
    {
        currentNode = binDataList.item(i);
        if(currentNode.getNodeType() == Node.ELEMENT_NODE && ((Element)currentNode).hasAttribute("w:name"))
        {               
            File newImageFile = new File(picDirectory, ((Element)currentNode).getAttribute("w:name").replaceFirst("wordml://", ""));
            if(newImageFile.exists())
            {

            }
            else
            {
                if(writeImage(newImageFile, currentNode))
                {
                    //Print some success message
                }
            }
        }
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
320 views
Welcome To Ask or Share your Answers For Others

1 Answer

Have a look at AndroidDocxToHtml, which I made to demonstrate using docx4j on Android.

A couple of caveats.

First, that project does not include all docx4j dependencies, only the ones required for docx to HTML conversion. So if you want to do other things, you may need others of the dependencies.

Second, docx4j requires JAXB - see this blog post re JAXB on Android - and JAXB context init on app startup takes a while depending on the device. There are ways to work around this, but at extra effort.

If all you want to do is extract the images, and you don't care how they relate to the text, you could just look for image parts. You might use OpenXML4J for that, and avoid JAXB.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...