Search in sources :

Example 41 with HSLFSlideShow

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

the class TestShapes method graphics.

@Test
public void graphics() throws IOException {
    HSLFSlide slide = ppt.createSlide();
    HSLFLine line = new HSLFLine();
    java.awt.Rectangle lineAnchor = new java.awt.Rectangle(100, 200, 50, 60);
    line.setAnchor(lineAnchor);
    line.setLineWidth(3);
    line.setLineDash(LineDash.DASH);
    line.setLineColor(Color.red);
    slide.addShape(line);
    HSLFAutoShape ellipse = new HSLFAutoShape(ShapeType.ELLIPSE);
    Rectangle2D ellipseAnchor = new Rectangle2D.Double(320, 154, 55, 111);
    ellipse.setAnchor(ellipseAnchor);
    ellipse.setLineWidth(2);
    ellipse.setLineDash(LineDash.SOLID);
    ellipse.setLineColor(Color.green);
    ellipse.setFillColor(Color.lightGray);
    slide.addShape(ellipse);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ppt.write(out);
    out.close();
    //read ppt from byte array
    HSLFSlideShow ppt2 = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
    assertEquals(1, ppt2.getSlides().size());
    slide = ppt2.getSlides().get(0);
    List<HSLFShape> shape = slide.getShapes();
    assertEquals(2, shape.size());
    //group shape
    assertTrue(shape.get(0) instanceof HSLFLine);
    //group shape
    assertEquals(lineAnchor, shape.get(0).getAnchor());
    //group shape
    assertTrue(shape.get(1) instanceof HSLFAutoShape);
    //group shape
    assertEquals(ellipseAnchor, shape.get(1).getAnchor());
    ppt2.close();
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFLine(org.apache.poi.hslf.usermodel.HSLFLine) HSLFShape(org.apache.poi.hslf.usermodel.HSLFShape) ByteArrayInputStream(java.io.ByteArrayInputStream) HSLFAutoShape(org.apache.poi.hslf.usermodel.HSLFAutoShape) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) Test(org.junit.Test)

Example 42 with HSLFSlideShow

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

the class TestExtractor method testExtractFromOwnEmbeded.

/**
     * A powerpoint file with embeded powerpoint files
     */
@Test
public void testExtractFromOwnEmbeded() throws IOException {
    PowerPointExtractor ppe = openExtractor("ppt_with_embeded.ppt");
    List<OLEShape> shapes = ppe.getOLEShapes();
    assertEquals("Expected 6 ole shapes", 6, shapes.size());
    int num_ppt = 0, num_doc = 0, num_xls = 0;
    for (OLEShape ole : shapes) {
        String name = ole.getInstanceName();
        InputStream data = ole.getObjectData().getData();
        if ("Worksheet".equals(name)) {
            HSSFWorkbook wb = new HSSFWorkbook(data);
            num_xls++;
            wb.close();
        } else if ("Document".equals(name)) {
            HWPFDocument doc = new HWPFDocument(data);
            num_doc++;
            doc.close();
        } else if ("Presentation".equals(name)) {
            num_ppt++;
            HSLFSlideShow ppt = new HSLFSlideShow(data);
            ppt.close();
        }
        data.close();
    }
    assertEquals("Expected 2 embedded Word Documents", 2, num_doc);
    assertEquals("Expected 2 embedded Excel Spreadsheets", 2, num_xls);
    assertEquals("Expected 2 embedded PowerPoint Presentations", 2, num_ppt);
    ppe.close();
}
Also used : HWPFDocument(org.apache.poi.hwpf.HWPFDocument) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) OLEShape(org.apache.poi.hslf.model.OLEShape) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 43 with HSLFSlideShow

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

the class TestBackground method getFillPictureRefCount.

private int getFillPictureRefCount(HSLFShape shape, HSLFFill fill) {
    AbstractEscherOptRecord opt = shape.getEscherOptRecord();
    EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__PATTERNTEXTURE);
    if (p != null) {
        int idx = p.getPropertyValue();
        HSLFSheet sheet = shape.getSheet();
        HSLFSlideShow ppt = sheet.getSlideShow();
        Document doc = ppt.getDocumentRecord();
        EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer();
        EscherContainerRecord bstore = HSLFShape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER);
        List<EscherRecord> lst = bstore.getChildRecords();
        return ((EscherBSERecord) lst.get(idx - 1)).getRef();
    }
    return 0;
}
Also used : EscherSimpleProperty(org.apache.poi.ddf.EscherSimpleProperty) HSLFSheet(org.apache.poi.hslf.usermodel.HSLFSheet) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) Document(org.apache.poi.hslf.record.Document) AbstractEscherOptRecord(org.apache.poi.ddf.AbstractEscherOptRecord) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord)

Example 44 with HSLFSlideShow

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

the class TestBackground method defaults.

/**
     * Default background for slide, shape and slide master.
     */
@Test
public void defaults() throws IOException {
    HSLFSlideShow ppt = new HSLFSlideShow();
    assertEquals(HSLFFill.FILL_SOLID, ppt.getSlideMasters().get(0).getBackground().getFill().getFillType());
    HSLFSlide slide = ppt.createSlide();
    assertTrue(slide.getFollowMasterBackground());
    assertEquals(HSLFFill.FILL_SOLID, slide.getBackground().getFill().getFillType());
    HSLFShape shape = new HSLFAutoShape(ShapeType.RECT);
    assertEquals(HSLFFill.FILL_SOLID, shape.getFill().getFillType());
    ppt.close();
}
Also used : HSLFShape(org.apache.poi.hslf.usermodel.HSLFShape) HSLFAutoShape(org.apache.poi.hslf.usermodel.HSLFAutoShape) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) Test(org.junit.Test)

Example 45 with HSLFSlideShow

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

the class TestHeadersFooters method testCreateNotesFooters.

@Test
public void testCreateNotesFooters() throws IOException {
    HSLFSlideShow ppt1 = new HSLFSlideShow();
    HeadersFooters hdd = ppt1.getNotesHeadersFooters();
    hdd.setFootersText("My notes footer");
    hdd.setHeaderText("My notes header");
    hdd.setSlideNumberVisible(true);
    HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1);
    HeadersFooters hdd2 = ppt2.getNotesHeadersFooters();
    assertTrue(hdd2.isSlideNumberVisible());
    assertTrue(hdd2.isFooterVisible());
    assertEquals("My notes footer", hdd2.getFooterText());
    assertTrue(hdd2.isHeaderVisible());
    assertEquals("My notes header", hdd2.getHeaderText());
    ppt2.close();
    ppt1.close();
}
Also used : HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) Test(org.junit.Test)

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