How to Read images from word(DOC) file and add it

2019-09-22 06:51发布

问题:

I have a doc file that contains text,images etc etc.

Now I want to read that doc file and write those contents into pdf file. My DOC file and newly generated PDF file has to be same.

I repeat, My DOC file contains ( "images as well as text" data ).

If anyone have this code please help me out.

Thank you so much for your time..

回答1:

You can use this code to get all the images from your document.

HWPFDocument doc = new HWPFDocument(fs);// fs is the object of POIFSFileSystem 
Range range = doc.getRange();
PicturesTable pt = doc.getPicturesTable();
List<Picture> listPic = pt.getAllPictures();
Picture pic = listPic.get(0);// iterate listPic upto its size to get images
byte[] picArr = pic.getContent();