Example usage for org.apache.poi.hpsf Thumbnail getThumbnailAsWMF

List of usage examples for org.apache.poi.hpsf Thumbnail getThumbnailAsWMF

Introduction

In this page you can find the example usage for org.apache.poi.hpsf Thumbnail getThumbnailAsWMF.

Prototype

public byte[] getThumbnailAsWMF() throws HPSFException 

Source Link

Document

<p>Returns the Thumbnail as a <code>byte[]</code> of WMF data if the Thumbnail's Clipboard Format Tag is #CFTAG_WINDOWS CFTAG_WINDOWS and its Clipboard Format is #CF_METAFILEPICT CF_METAFILEPICT </p> <p>This <code>byte[]</code> is in the traditional WMF file, not the clipboard-specific version with special headers.</p> <p>See <a href="http://www.wvware.com/caolan/ora-wmf.html" target="_blank">http://www.wvware.com/caolan/ora-wmf.html</a> for more information on the WMF image format.</p>

Usage

From source file:com.oneis.graphics.ThumbnailFinder.java

License:Mozilla Public License

/**
 * Try and get a thumbnail from an old Microsoft Office document
 *///ww w  .j av a2  s  . c om
private void findFromOldMSOffice() {
    try {
        File poiFilesystem = new File(inFilename);

        // Open the POI filesystem.
        InputStream is = new FileInputStream(poiFilesystem);
        POIFSFileSystem poifs = new POIFSFileSystem(is);
        is.close();

        // Read the summary information.
        DirectoryEntry dir = poifs.getRoot();
        DocumentEntry siEntry = (DocumentEntry) dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME);
        DocumentInputStream dis = new DocumentInputStream(siEntry);
        PropertySet ps = new PropertySet(dis);
        dis.close();
        SummaryInformation si = new SummaryInformation(ps);
        if (si != null) {
            byte[] thumbnailData = si.getThumbnail();
            if (thumbnailData != null) {
                Thumbnail thumbnail = new Thumbnail(thumbnailData);
                byte[] wmf = thumbnail.getThumbnailAsWMF();
                // Got something!
                thumbnailDimensions = tryWMFFormat(new ByteArrayInputStream(wmf), outFilename, outFormat,
                        maxDimension);
            }
        }
    } catch (Exception e) {
        logIgnoredException("ThumbnailFinder Apache POI file reading failed", e);
    }
}