title: How to extract data from a .docx file including image, table, formula etc?
body: <p>I am doing a task in which i have to extract data from word document mainly images, tables and special texts(formula etc) .</p>
  
  <p>I am able to save image from a word file it is downloaded from web but when i am applying same code to my .docx file than it is giving error.</p>
  
  <p>Code for same is</p>
  
  <pre><code>//create file inputstream to read from a binary file
        FileInputStream fs=new FileInputStream(filename);
        //create office word 2007+ document object to wrap the word file
        XWPFDocument docx=new XWPFDocument(fs);
        //get all images from the document and store them in the list piclist
        List&lt;XWPFPictureData&gt; piclist=docx.getAllPictures();
        //traverse through the list and write each image to a file
        Iterator&lt;XWPFPictureData&gt; iterator=piclist.iterator();
        System.out.println(piclist.size());
        while(iterator.hasNext()){
  
         XWPFPictureData pic=iterator.next();
         byte[] bytepic=pic.getData();
         int i=0;
         BufferedImage imag=ImageIO.read(new ByteArrayInputStream(bytepic));
         //captureimage(imag,i,flag,j);
         if(imag != null)
         {
                 ImageIO.write(imag, "jpg", new File("D:/imagefromword"+i+".jpg"));  
         }else{
             System.out.println("imag is empty");
         }
  </code></pre>
  
  <p>It is giving incorrect format error. But I cannot change the doc file.
  Secondly for above code if i am having more then one image and when i am saving this than every time it saving save image. Suppose we have 3 images then it will save 3 images but all three will be latest one.</p>
  
  <p>Any help will be appreciated. </p>