Search in sources :

Example 1 with HSLFSlideShow

use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.

the class BulletsDemo method main.

public static void main(String[] args) throws IOException {
    HSLFSlideShow ppt = new HSLFSlideShow();
    try {
        HSLFSlide slide = ppt.createSlide();
        HSLFTextBox shape = new HSLFTextBox();
        HSLFTextParagraph rt = shape.getTextParagraphs().get(0);
        rt.getTextRuns().get(0).setFontSize(42d);
        rt.setBullet(true);
        //bullet offset
        rt.setIndent(0d);
        //text offset (should be greater than bullet offset)
        rt.setLeftMargin(50d);
        //bullet character
        rt.setBulletChar('☺');
        shape.setText("January\r" + "February\r" + "March\r" + "April");
        slide.addShape(shape);
        //position of the text box in the slide
        shape.setAnchor(new java.awt.Rectangle(50, 50, 500, 300));
        slide.addShape(shape);
        FileOutputStream out = new FileOutputStream("bullets.ppt");
        ppt.write(out);
        out.close();
    } finally {
        ppt.close();
    }
}
Also used : HSLFTextBox(org.apache.poi.hslf.usermodel.HSLFTextBox) HSLFTextParagraph(org.apache.poi.hslf.usermodel.HSLFTextParagraph) FileOutputStream(java.io.FileOutputStream) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide)

Example 2 with HSLFSlideShow

use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.

the class DataExtraction method main.

public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        usage();
        return;
    }
    FileInputStream is = new FileInputStream(args[0]);
    HSLFSlideShow ppt = new HSLFSlideShow(is);
    is.close();
    //extract all sound files embedded in this presentation
    HSLFSoundData[] sound = ppt.getSoundData();
    for (int i = 0; i < sound.length; i++) {
        //*.wav
        String type = sound[i].getSoundType();
        //typically file name
        String name = sound[i].getSoundName();
        //raw bytes
        byte[] data = sound[i].getData();
        //save the sound  on disk
        FileOutputStream out = new FileOutputStream(name + type);
        out.write(data);
        out.close();
    }
    int oleIdx = -1, picIdx = -1;
    for (HSLFSlide slide : ppt.getSlides()) {
        //extract embedded OLE documents
        for (HSLFShape shape : slide.getShapes()) {
            if (shape instanceof OLEShape) {
                oleIdx++;
                OLEShape ole = (OLEShape) shape;
                HSLFObjectData data = ole.getObjectData();
                String name = ole.getInstanceName();
                if ("Worksheet".equals(name)) {
                    //read xls
                    @SuppressWarnings({ "unused", "resource" }) HSSFWorkbook wb = new HSSFWorkbook(data.getData());
                } else if ("Document".equals(name)) {
                    HWPFDocument doc = new HWPFDocument(data.getData());
                    //read the word document
                    Range r = doc.getRange();
                    for (int k = 0; k < r.numParagraphs(); k++) {
                        Paragraph p = r.getParagraph(k);
                        System.out.println(p.text());
                    }
                    //save on disk
                    FileOutputStream out = new FileOutputStream(name + "-(" + (oleIdx) + ").doc");
                    doc.write(out);
                    out.close();
                    doc.close();
                } else {
                    FileOutputStream out = new FileOutputStream(ole.getProgID() + "-" + (oleIdx + 1) + ".dat");
                    InputStream dis = data.getData();
                    byte[] chunk = new byte[2048];
                    int count;
                    while ((count = dis.read(chunk)) >= 0) {
                        out.write(chunk, 0, count);
                    }
                    is.close();
                    out.close();
                }
            } else //Pictures
            if (shape instanceof HSLFPictureShape) {
                picIdx++;
                HSLFPictureShape p = (HSLFPictureShape) shape;
                HSLFPictureData data = p.getPictureData();
                String ext = data.getType().extension;
                FileOutputStream out = new FileOutputStream("pict-" + picIdx + ext);
                out.write(data.getData());
                out.close();
            }
        }
    }
    ppt.close();
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) HSLFObjectData(org.apache.poi.hslf.usermodel.HSLFObjectData) Range(org.apache.poi.hwpf.usermodel.Range) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) FileInputStream(java.io.FileInputStream) OLEShape(org.apache.poi.hslf.model.OLEShape) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Paragraph(org.apache.poi.hwpf.usermodel.Paragraph) HWPFDocument(org.apache.poi.hwpf.HWPFDocument) HSLFShape(org.apache.poi.hslf.usermodel.HSLFShape) HSLFPictureShape(org.apache.poi.hslf.usermodel.HSLFPictureShape) FileOutputStream(java.io.FileOutputStream) HSLFSoundData(org.apache.poi.hslf.usermodel.HSLFSoundData) HSLFPictureData(org.apache.poi.hslf.usermodel.HSLFPictureData) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide)

Example 3 with HSLFSlideShow

use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.

the class HeadersFootersDemo method main.

public static void main(String[] args) throws IOException {
    HSLFSlideShow ppt = new HSLFSlideShow();
    try {
        HeadersFooters slideHeaders = ppt.getSlideHeadersFooters();
        slideHeaders.setFootersText("Created by POI-HSLF");
        slideHeaders.setSlideNumberVisible(true);
        slideHeaders.setDateTimeText("custom date time");
        HeadersFooters notesHeaders = ppt.getNotesHeadersFooters();
        notesHeaders.setFootersText("My notes footers");
        notesHeaders.setHeaderText("My notes header");
        ppt.createSlide();
        FileOutputStream out = new FileOutputStream("headers_footers.ppt");
        ppt.write(out);
        out.close();
    } finally {
        ppt.close();
    }
}
Also used : HeadersFooters(org.apache.poi.hslf.model.HeadersFooters) FileOutputStream(java.io.FileOutputStream) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow)

Example 4 with HSLFSlideShow

use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.

the class PPT2PNG method main.

public static void main(String[] args) throws IOException {
    if (args.length == 0) {
        usage();
        return;
    }
    int slidenum = -1;
    float scale = 1;
    String file = null;
    for (int i = 0; i < args.length; i++) {
        if (args[i].startsWith("-")) {
            if ("-scale".equals(args[i])) {
                scale = Float.parseFloat(args[++i]);
            } else if ("-slide".equals(args[i])) {
                slidenum = Integer.parseInt(args[++i]);
            }
        } else {
            file = args[i];
        }
    }
    if (file == null) {
        usage();
        return;
    }
    FileInputStream is = new FileInputStream(file);
    HSLFSlideShow ppt = new HSLFSlideShow(is);
    is.close();
    Dimension pgsize = ppt.getPageSize();
    int width = (int) (pgsize.width * scale);
    int height = (int) (pgsize.height * scale);
    for (HSLFSlide slide : ppt.getSlides()) {
        if (slidenum != -1 && slidenum != slide.getSlideNumber()) {
            continue;
        }
        String title = slide.getTitle();
        System.out.println("Rendering slide " + slide.getSlideNumber() + (title == null ? "" : ": " + title));
        BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics2D graphics = img.createGraphics();
        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
        graphics.setPaint(Color.white);
        graphics.fill(new Rectangle2D.Float(0, 0, width, height));
        graphics.scale((double) width / pgsize.width, (double) height / pgsize.height);
        slide.draw(graphics);
        String fname = file.replaceAll("\\.ppt", "-" + slide.getSlideNumber() + ".png");
        FileOutputStream out = new FileOutputStream(fname);
        ImageIO.write(img, "png", out);
        out.close();
    }
    ppt.close();
}
Also used : FileOutputStream(java.io.FileOutputStream) Rectangle2D(java.awt.geom.Rectangle2D) Dimension(java.awt.Dimension) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) FileInputStream(java.io.FileInputStream) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 5 with HSLFSlideShow

use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.

the class SoundFinder method main.

public static void main(String[] args) throws IOException {
    FileInputStream fis = new FileInputStream(args[0]);
    HSLFSlideShow ppt = new HSLFSlideShow(fis);
    HSLFSoundData[] sounds = ppt.getSoundData();
    for (HSLFSlide slide : ppt.getSlides()) {
        for (HSLFShape shape : slide.getShapes()) {
            int soundRef = getSoundReference(shape);
            if (soundRef == -1)
                continue;
            System.out.println("Slide[" + slide.getSlideNumber() + "], shape[" + shape.getShapeId() + "], soundRef: " + soundRef);
            System.out.println("  " + sounds[soundRef].getSoundName());
            System.out.println("  " + sounds[soundRef].getSoundType());
        }
    }
    ppt.close();
    fis.close();
}
Also used : HSLFShape(org.apache.poi.hslf.usermodel.HSLFShape) HSLFSoundData(org.apache.poi.hslf.usermodel.HSLFSoundData) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) FileInputStream(java.io.FileInputStream)

Aggregations

HSLFSlideShow (org.apache.poi.hslf.usermodel.HSLFSlideShow)69 Test (org.junit.Test)42 HSLFSlide (org.apache.poi.hslf.usermodel.HSLFSlide)39 HSLFShape (org.apache.poi.hslf.usermodel.HSLFShape)17 ByteArrayInputStream (java.io.ByteArrayInputStream)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 InputStream (java.io.InputStream)10 FileOutputStream (java.io.FileOutputStream)9 HSLFTextRun (org.apache.poi.hslf.usermodel.HSLFTextRun)9 HSLFTextParagraph (org.apache.poi.hslf.usermodel.HSLFTextParagraph)8 Rectangle2D (java.awt.geom.Rectangle2D)7 FileInputStream (java.io.FileInputStream)7 HSLFPictureData (org.apache.poi.hslf.usermodel.HSLFPictureData)7 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)7 HWPFDocument (org.apache.poi.hwpf.HWPFDocument)7 HSLFSlideShowImpl (org.apache.poi.hslf.usermodel.HSLFSlideShowImpl)6 HSLFTextBox (org.apache.poi.hslf.usermodel.HSLFTextBox)5 POIDataSamples (org.apache.poi.POIDataSamples)4 Record (org.apache.poi.hslf.record.Record)4 HSLFHyperlink (org.apache.poi.hslf.usermodel.HSLFHyperlink)4