Example usage for org.apache.poi.xslf.usermodel XSLFPictureShape getPictureData

List of usage examples for org.apache.poi.xslf.usermodel XSLFPictureShape getPictureData

Introduction

In this page you can find the example usage for org.apache.poi.xslf.usermodel XSLFPictureShape getPictureData.

Prototype

public XSLFPictureData getPictureData() 

Source Link

Document

Return the data on the (internal) picture.

Usage

From source file:poi.xslf.usermodel.DataExtraction.java

License:Apache License

public static void main(String args[]) throws Exception {

    if (args.length == 0) {
        System.out.println("Input file is required");
        return;// w ww.j  av a  2  s .co  m
    }

    FileInputStream is = new FileInputStream(args[0]);
    XMLSlideShow ppt = new XMLSlideShow(is);
    is.close();

    // Get the document's embedded files.
    List<PackagePart> embeds = ppt.getAllEmbedds();
    for (PackagePart p : embeds) {
        String type = p.getContentType();
        String name = p.getPartName().getName(); //typically file name

        InputStream pIs = p.getInputStream();
        // make sense of the part data
        pIs.close();

    }

    // Get the document's embedded files.
    List<XSLFPictureData> images = ppt.getAllPictures();
    for (XSLFPictureData data : images) {
        PackagePart p = data.getPackagePart();

        String type = p.getContentType();
        String name = data.getFileName();

        InputStream pIs = p.getInputStream();
        // make sense of the image data
        pIs.close();

    }

    Dimension pageSize = ppt.getPageSize(); // size of the canvas in points
    for (XSLFSlide slide : ppt.getSlides()) {
        for (XSLFShape shape : slide) {
            Rectangle2D anchor = shape.getAnchor(); // position on the canvas
            if (shape instanceof XSLFTextShape) {
                XSLFTextShape txShape = (XSLFTextShape) shape;
                System.out.println(txShape.getText());
            } else if (shape instanceof XSLFPictureShape) {
                XSLFPictureShape pShape = (XSLFPictureShape) shape;
                XSLFPictureData pData = pShape.getPictureData();
                System.out.println(pData.getFileName());
            } else {
                System.out.println("Process me: " + shape.getClass());
            }
        }
    }
}