Search in sources :

Example 1 with HSLFSlide

use of org.apache.poi.hslf.usermodel.HSLFSlide 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 HSLFSlide

use of org.apache.poi.hslf.usermodel.HSLFSlide 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 HSLFSlide

use of org.apache.poi.hslf.usermodel.HSLFSlide 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 4 with HSLFSlide

use of org.apache.poi.hslf.usermodel.HSLFSlide 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)

Example 5 with HSLFSlide

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

the class TestSlideMaster method testIndentation.

/**
     * Varify we can read attrubutes for different identtation levels.
     * (typical for the "bullted body" placeholder)
     */
@Test
public void testIndentation() throws IOException {
    HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
    HSLFSlide slide = ppt.getSlides().get(0);
    for (List<HSLFTextParagraph> tparas : slide.getTextParagraphs()) {
        HSLFTextParagraph tpara = tparas.get(0);
        if (tpara.getRunType() == TextHeaderAtom.TITLE_TYPE) {
            HSLFTextRun rt = tpara.getTextRuns().get(0);
            assertEquals(40, rt.getFontSize(), 0);
            assertEquals(true, rt.isUnderlined());
            assertEquals("Arial", rt.getFontFamily());
        } else if (tpara.getRunType() == TextHeaderAtom.BODY_TYPE) {
            int[] indents = { 32, 28, 24 };
            for (HSLFTextRun rt : tpara.getTextRuns()) {
                int indent = tpara.getIndentLevel();
                assertEquals(indents[indent], rt.getFontSize(), 0);
            }
        }
    }
    ppt.close();
}
Also used : HSLFTextRun(org.apache.poi.hslf.usermodel.HSLFTextRun) HSLFTextParagraph(org.apache.poi.hslf.usermodel.HSLFTextParagraph) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) Test(org.junit.Test)

Aggregations

HSLFSlide (org.apache.poi.hslf.usermodel.HSLFSlide)43 HSLFSlideShow (org.apache.poi.hslf.usermodel.HSLFSlideShow)39 Test (org.junit.Test)32 HSLFShape (org.apache.poi.hslf.usermodel.HSLFShape)17 ByteArrayInputStream (java.io.ByteArrayInputStream)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 HSLFTextRun (org.apache.poi.hslf.usermodel.HSLFTextRun)9 HSLFTextParagraph (org.apache.poi.hslf.usermodel.HSLFTextParagraph)8 Rectangle2D (java.awt.geom.Rectangle2D)7 FileOutputStream (java.io.FileOutputStream)6 HSLFPictureData (org.apache.poi.hslf.usermodel.HSLFPictureData)6 HSLFTextBox (org.apache.poi.hslf.usermodel.HSLFTextBox)6 InputStream (java.io.InputStream)5 FileInputStream (java.io.FileInputStream)4 HeadersFooters (org.apache.poi.hslf.model.HeadersFooters)4 HSLFHyperlink (org.apache.poi.hslf.usermodel.HSLFHyperlink)4 HSLFLine (org.apache.poi.hslf.usermodel.HSLFLine)4 HSLFTable (org.apache.poi.hslf.usermodel.HSLFTable)4 HSLFAutoShape (org.apache.poi.hslf.usermodel.HSLFAutoShape)3 Dimension (java.awt.Dimension)2