解析docx以及doc格式的word文档中的图片

解析docx以及doc格式的word文档中的图片

ID:6052073

大小:49.50 KB

页数:5页

时间:2018-01-01

解析docx以及doc格式的word文档中的图片_第1页
解析docx以及doc格式的word文档中的图片_第2页
解析docx以及doc格式的word文档中的图片_第3页
解析docx以及doc格式的word文档中的图片_第4页
解析docx以及doc格式的word文档中的图片_第5页
资源描述:

《解析docx以及doc格式的word文档中的图片》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、上海傲蓝科技用Java从Doc和Docx格式的Word文档中提取图片Doc和Docx的文档格式因为存储格式不一样,所以需要用不通的方法提取图片。Docx格式的文档实际上是压缩文件,用程序提取图片相对实际上只需要对文章进行解压缩,然后到指定文件夹找到图片即可。Doc文档则需要把图片数据读出来,再生成文件。下面代码均可直接运行。从Docx文件中提取图片的代码:packagecom.onlan.docx;importjava.io.BufferedInputStream;importjava.io.BufferedOutputStream;importjava.io.File;importja

2、va.io.FileOutputStream;importjava.util.Enumeration;importjava.util.zip.ZipEntry;importjava.util.zip.ZipFile;publicclassImgExt4Docx{/***@paramargs*/staticfinalintBUFFER=2048;publicstaticvoidmain(String[]args){StringinputFilename="D:/work/test.docx";StringunZipPathname="D:/work/unZipDir/";ImgExt4Do

3、cxied=newImgExt4Docx();System.out.println(ied.unZipDocx(inputFilename,unZipPathname));}/**returnthefoldoftheimages*/publicStringunZipDocx(Stringdocxfile,StringdestDir)5上海傲蓝科技{try{StringinputFilename=docxfile;StringunZipPathname=destDir;ZipFilezipFile=newZipFile(inputFilename);Enumerationenu=zipFi

4、le.entries();inti=0;while(enu.hasMoreElements()){ZipEntryzipEntry=(ZipEntry)enu.nextElement();if(zipEntry.isDirectory()){newFile(unZipPathname+zipEntry.getName()).mkdirs();continue;}BufferedInputStreambis=newBufferedInputStream(zipFile.getInputStream(zipEntry));Filefile=newFile(unZipPathname+zipE

5、ntry.getName());Fileparent=file.getParentFile();if(parent!=null&&!parent.exists()){parent.mkdirs();}FileOutputStreamfos=newFileOutputStream(file);BufferedOutputStreambos=newBufferedOutputStream(fos,BUFFER);intcount;byte[]array=newbyte[BUFFER];while((count=bis.read(array,0,BUFFER))!=-1){bos.write(

6、array,0,BUFFER);}bos.flush();bos.close();bis.close();}returndestDir+"word/media";}catch(Exceptione){e.printStackTrace();returnnull;}}5上海傲蓝科技}从Doc文件中提取图片的代码,该代码不仅可以从文档中提取图片,还可以把Doc文档中图片所在位置加上标签以及图片文件名,与提取的图片对应起来:packagecom.onlan;importjava.io.File;importjava.io.FileInputStream;importjava.io.FileOu

7、tputStream;importjava.io.InputStream;importjava.io.OutputStream;importorg.apache.poi.hwpf.HWPFDocument;importorg.apache.poi.hwpf.model.PicturesTable;importorg.apache.poi.hwpf.usermodel.CharacterRun;importorg.apache.poi

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。