FileDocCategorySizeDatePackage
ImageExtractor.javaAPI DocApache Poi 3.0.12791Sun Mar 11 12:59:30 GMT 2007org.apache.poi.hslf.extractor

ImageExtractor

public class ImageExtractor extends Object
Utility to extract pictures from a PowerPoint file.
author
Yegor Kozlov

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

        if (args.length < 1) {
            System.err.println("Usage:");
            System.err.println("\tImageExtractor <file>");
            return;
        }
        SlideShow ppt = new SlideShow(new HSLFSlideShow(args[0]));

        //extract all pictures contained in the presentation
        PictureData[] pdata = ppt.getPictureData();
        for (int i = 0; i < pdata.length; i++) {
            PictureData pict = pdata[i];

            // picture data
            byte[] data = pict.getData();

            int type = pict.getType();
            String ext;
            switch (type) {
                case Picture.JPEG:
                    ext = ".jpg";
                    break;
                case Picture.PNG:
                    ext = ".png";
                    break;
                case Picture.WMF:
                    ext = ".wmf";
                    break;
                case Picture.EMF:
                    ext = ".emf";
                    break;
                case Picture.PICT:
                    ext = ".pict";
                    break;
                case Picture.DIB:
                    ext = ".dib";
                    break;
                default:
                    continue;
            }
            FileOutputStream out = new FileOutputStream("pict_" + i + ext);
            out.write(data);
            out.close();
        }