使用Apache POI得到单词的缩略在java中 [英] get thumbnail of word in java using Apache POI

查看:265
本文介绍了使用Apache POI得到单词的缩略在java中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在jsf.In网络共享工程这个项目的用户可以上传文件,如.doc,.PDF,.PPT,.​​.等研究。我想表明,该文档第一页的缩略图。一些谷歌上搜索周围后,我发现阿帕奇POI.Can有人有我的问题有何建议?我怎样才能返回Word文档的第一页的缩略图?我试试这个code.This code刚刚获得第一张图片的Word文档中包含:

  POIFSFileSystem FS =新POIFSFileSystem(新的FileInputStream(D:\\\\ Test.doc的));
        HWPFDocument DOC =新HWPFDocument(FS);
        PicturesTable PT = doc.getPicturesTable();
        清单<图片和GT; p值= pt.getAllPictures();
        BufferedImage的图像= ImageIO.read(新ByteArrayInputStream进行(p.get(0).getContent()));
        ImageIO.write(图像,JPG,新的文件(D:\\\\ test.jpg放在));


解决方案

什么是你在做什么都不做。 HWPFDocument可以提取嵌入在文件的缩略图(保存文件时,请查看添加preVIEW'选项)。因此HWPFDocument可以提取具有缩略图文件缩略图仅

甚至,要做到这一点,你必须做出:
{code}

 字节的静态[]工艺(文件DOCFILE)抛出异常{
    最后HWPFDocumentCore wordDocument = AbstractWordUtils.loadDoc(DOCFILE);
    的SummaryInformation的SummaryInformation = wordDocument.getSummaryInformation();
    的System.out.println(summaryInformation.getAuthor());
    的System.out.println(summaryInformation.getApplicationName()+:+ summaryInformation.getTitle());
    缩图=新的缩略图(summaryInformation.getThumbnail());
    的System.out.println(thumbnail.getClipboardFormat());
    的System.out.println(thumbnail.getClipboardFormatTag());
    返回thumbnail.getThumbnailAsWMF();
}

{code}
在这之后,你有可能WMF文件格式转换为较常见的格式(JPEG,PNG ...)。 ImageMagick的可以提供帮助。

I study on a web sharing project in jsf.In this project users can upload documents such as .doc,.pdf,.ppt,..etc . I want show this documents first pages as a thumbnail. After some googling around I found Apache POI.Can anybody has any suggestion for my problem? How can I return thumbnail image of word doc's first page? I try this code.This code just get first picture that word doc contains:

        POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("d:\\test.doc"));
        HWPFDocument doc = new HWPFDocument(fs);
        PicturesTable pt=doc.getPicturesTable();
        List<Picture> p=pt.getAllPictures();
        BufferedImage image=ImageIO.read(new ByteArrayInputStream(p.get(0).getContent()));
        ImageIO.write(image, "JPG", new File("d:\\test.jpg"));

解决方案

What's you are doing make nothing. HWPFDocument can extract thumbnail embedded in document (when saving files, check on 'add preview' option). So HWPFDocument can extract only thumbnail of documents having thumbnail.

Even, to do that, you have to make: {code}

static byte[] process(File docFile) throws Exception {
    final HWPFDocumentCore wordDocument = AbstractWordUtils.loadDoc(docFile);
    SummaryInformation summaryInformation = wordDocument.getSummaryInformation();
    System.out.println(summaryInformation.getAuthor());
    System.out.println(summaryInformation.getApplicationName() + ":" + summaryInformation.getTitle());
    Thumbnail thumbnail = new Thumbnail(summaryInformation.getThumbnail());
    System.out.println(thumbnail.getClipboardFormat());
    System.out.println(thumbnail.getClipboardFormatTag());
    return thumbnail.getThumbnailAsWMF();
}

{code} after that, you have to probably convert WMF file format to more common format (jpeg, png...). ImageMagick can help.

这篇关于使用Apache POI得到单词的缩略在java中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆