Search in sources :

Example 51 with HSLFSlideShow

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

the class TestLine method testCreateLines.

@Test
public void testCreateLines() throws IOException {
    HSLFSlideShow ppt = new HSLFSlideShow();
    HSLFSlide slide = ppt.createSlide();
    slide.addTitle().setText("Lines tester");
    HSLFLine line;
    /**
         * line styles
         */
    line = new HSLFLine();
    line.setAnchor(new java.awt.Rectangle(75, 200, 300, 0));
    line.setLineCompound(LineCompound.SINGLE);
    line.setLineColor(Color.blue);
    slide.addShape(line);
    line = new HSLFLine();
    line.setAnchor(new java.awt.Rectangle(75, 230, 300, 0));
    line.setLineCompound(LineCompound.DOUBLE);
    line.setLineWidth(3.5);
    slide.addShape(line);
    line = new HSLFLine();
    line.setAnchor(new java.awt.Rectangle(75, 260, 300, 0));
    line.setLineCompound(LineCompound.TRIPLE);
    line.setLineWidth(6);
    slide.addShape(line);
    line = new HSLFLine();
    line.setAnchor(new java.awt.Rectangle(75, 290, 300, 0));
    line.setLineCompound(LineCompound.THICK_THIN);
    line.setLineWidth(4.5);
    slide.addShape(line);
    line = new HSLFLine();
    line.setAnchor(new java.awt.Rectangle(75, 320, 300, 0));
    line.setLineCompound(LineCompound.THIN_THICK);
    line.setLineWidth(5.5);
    slide.addShape(line);
    /**
         * line dashing
         */
    line = new HSLFLine();
    line.setAnchor(new java.awt.Rectangle(450, 200, 300, 0));
    line.setLineDash(LineDash.SOLID);
    slide.addShape(line);
    line = new HSLFLine();
    line.setAnchor(new java.awt.Rectangle(450, 230, 300, 0));
    line.setLineDash(LineDash.DASH);
    slide.addShape(line);
    line = new HSLFLine();
    line.setAnchor(new java.awt.Rectangle(450, 260, 300, 0));
    line.setLineDash(LineDash.DOT);
    slide.addShape(line);
    line = new HSLFLine();
    line.setAnchor(new java.awt.Rectangle(450, 290, 300, 0));
    line.setLineDash(LineDash.DASH_DOT);
    slide.addShape(line);
    line = new HSLFLine();
    line.setAnchor(new java.awt.Rectangle(450, 320, 300, 0));
    line.setLineDash(LineDash.LG_DASH_DOT_DOT);
    slide.addShape(line);
    /**
         * Combinations
         */
    line = new HSLFLine();
    line.setAnchor(new java.awt.Rectangle(75, 400, 300, 0));
    line.setLineDash(LineDash.DASH_DOT);
    line.setLineCompound(LineCompound.TRIPLE);
    line.setLineWidth(5.0);
    slide.addShape(line);
    line = new HSLFLine();
    line.setAnchor(new java.awt.Rectangle(75, 430, 300, 0));
    line.setLineDash(LineDash.DASH);
    line.setLineCompound(LineCompound.THICK_THIN);
    line.setLineWidth(4.0);
    slide.addShape(line);
    line = new HSLFLine();
    line.setAnchor(new java.awt.Rectangle(75, 460, 300, 0));
    line.setLineDash(LineDash.DOT);
    line.setLineCompound(LineCompound.DOUBLE);
    line.setLineWidth(8.0);
    slide.addShape(line);
    ppt.close();
}
Also used : HSLFLine(org.apache.poi.hslf.usermodel.HSLFLine) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) Test(org.junit.Test)

Example 52 with HSLFSlideShow

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

the class TestOleEmbedding method testEmbedding.

@Test
public void testEmbedding() throws IOException {
    HSLFSlideShow ppt = new HSLFSlideShow();
    File pict = POIDataSamples.getSlideShowInstance().getFile("clock.jpg");
    HSLFPictureData pictData = ppt.addPicture(pict, PictureType.JPEG);
    InputStream is = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("Employee.xls");
    POIFSFileSystem poiData1 = new POIFSFileSystem(is);
    is.close();
    int oleObjectId1 = ppt.addEmbed(poiData1);
    HSLFSlide slide1 = ppt.createSlide();
    OLEShape oleShape1 = new OLEShape(pictData);
    oleShape1.setObjectID(oleObjectId1);
    slide1.addShape(oleShape1);
    oleShape1.setAnchor(new Rectangle2D.Double(100, 100, 100, 100));
    // add second slide with different order in object creation
    HSLFSlide slide2 = ppt.createSlide();
    OLEShape oleShape2 = new OLEShape(pictData);
    is = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("SimpleWithImages.xls");
    POIFSFileSystem poiData2 = new POIFSFileSystem(is);
    is.close();
    int oleObjectId2 = ppt.addEmbed(poiData2);
    oleShape2.setObjectID(oleObjectId2);
    slide2.addShape(oleShape2);
    oleShape2.setAnchor(new Rectangle2D.Double(100, 100, 100, 100));
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ppt.write(bos);
    ppt = new HSLFSlideShow(new ByteArrayInputStream(bos.toByteArray()));
    OLEShape comp = (OLEShape) ppt.getSlides().get(0).getShapes().get(0);
    byte[] compData = IOUtils.toByteArray(comp.getObjectData().getData());
    bos.reset();
    poiData1.writeFilesystem(bos);
    byte[] expData = bos.toByteArray();
    assertArrayEquals(expData, compData);
    poiData1.close();
    poiData2.close();
    ppt.close();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Rectangle2D(java.awt.geom.Rectangle2D) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) ByteArrayInputStream(java.io.ByteArrayInputStream) POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) HSLFPictureData(org.apache.poi.hslf.usermodel.HSLFPictureData) File(java.io.File) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) Test(org.junit.Test)

Example 53 with HSLFSlideShow

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

the class TestOleEmbedding method testOLEShape.

@Test
public void testOLEShape() throws IOException {
    HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("ole2-embedding-2003.ppt"));
    HSLFSlide slide = ppt.getSlides().get(0);
    int cnt = 0;
    for (HSLFShape sh : slide.getShapes()) {
        if (sh instanceof OLEShape) {
            cnt++;
            OLEShape ole = (OLEShape) sh;
            HSLFObjectData data = ole.getObjectData();
            if ("Worksheet".equals(ole.getInstanceName())) {
                //Voila! we created a workbook from the embedded OLE data
                HSSFWorkbook wb = new HSSFWorkbook(data.getData());
                HSSFSheet sheet = wb.getSheetAt(0);
                //verify we can access the xls data
                assertEquals(1, sheet.getRow(0).getCell(0).getNumericCellValue(), 0);
                assertEquals(1, sheet.getRow(1).getCell(0).getNumericCellValue(), 0);
                assertEquals(2, sheet.getRow(2).getCell(0).getNumericCellValue(), 0);
                assertEquals(3, sheet.getRow(3).getCell(0).getNumericCellValue(), 0);
                assertEquals(8, sheet.getRow(5).getCell(0).getNumericCellValue(), 0);
                wb.close();
            } else if ("Document".equals(ole.getInstanceName())) {
                //creating a HWPF document
                HWPFDocument doc = new HWPFDocument(data.getData());
                String txt = doc.getRange().getParagraph(0).text();
                assertEquals("OLE embedding is thoroughly unremarkable.\r", txt);
                doc.close();
            }
        }
    }
    assertEquals("Expected 2 OLE shapes", 2, cnt);
    ppt.close();
}
Also used : HWPFDocument(org.apache.poi.hwpf.HWPFDocument) HSLFShape(org.apache.poi.hslf.usermodel.HSLFShape) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSLFObjectData(org.apache.poi.hslf.usermodel.HSLFObjectData) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 54 with HSLFSlideShow

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

the class TestSlideMaster method testTitleMasterTextAttributes.

/**
     * Test we can read default text attributes for a title master sheet
     */
@Test
public void testTitleMasterTextAttributes() throws IOException {
    HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
    List<HSLFTitleMaster> master = ppt.getTitleMasters();
    assertEquals(1, master.size());
    assertEquals(32, master.get(0).getStyleAttribute(TextHeaderAtom.CENTER_TITLE_TYPE, 0, "font.size", true).getValue());
    CharFlagsTextProp prop1 = (CharFlagsTextProp) master.get(0).getStyleAttribute(TextHeaderAtom.CENTER_TITLE_TYPE, 0, "char_flags", true);
    assertEquals(true, prop1.getSubValue(CharFlagsTextProp.BOLD_IDX));
    assertEquals(false, prop1.getSubValue(CharFlagsTextProp.ITALIC_IDX));
    assertEquals(true, prop1.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
    assertEquals(20, master.get(0).getStyleAttribute(TextHeaderAtom.CENTRE_BODY_TYPE, 0, "font.size", true).getValue());
    CharFlagsTextProp prop2 = (CharFlagsTextProp) master.get(0).getStyleAttribute(TextHeaderAtom.CENTRE_BODY_TYPE, 0, "char_flags", true);
    assertEquals(true, prop2.getSubValue(CharFlagsTextProp.BOLD_IDX));
    assertEquals(false, prop2.getSubValue(CharFlagsTextProp.ITALIC_IDX));
    assertEquals(false, prop2.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
    ppt.close();
}
Also used : HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) CharFlagsTextProp(org.apache.poi.hslf.model.textproperties.CharFlagsTextProp) HSLFTitleMaster(org.apache.poi.hslf.usermodel.HSLFTitleMaster) Test(org.junit.Test)

Example 55 with HSLFSlideShow

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

the class TestSlideMaster method testTitleMaster.

/**
     * Slide 3 has title layout and follows the TitleMaster. Verify that.
     */
@Test
public void testTitleMaster() throws IOException {
    HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
    HSLFSlide slide = ppt.getSlides().get(2);
    HSLFMasterSheet masterSheet = slide.getMasterSheet();
    assertTrue(masterSheet instanceof HSLFTitleMaster);
    for (List<HSLFTextParagraph> txt : slide.getTextParagraphs()) {
        HSLFTextRun rt = txt.get(0).getTextRuns().get(0);
        switch(txt.get(0).getRunType()) {
            case TextHeaderAtom.CENTER_TITLE_TYPE:
                assertEquals("Arial", rt.getFontFamily());
                assertEquals(32, rt.getFontSize(), 0);
                assertEquals(true, rt.isBold());
                assertEquals(true, rt.isUnderlined());
                break;
            case TextHeaderAtom.CENTRE_BODY_TYPE:
                assertEquals("Courier New", rt.getFontFamily());
                assertEquals(20, rt.getFontSize(), 0);
                assertEquals(true, rt.isBold());
                assertEquals(false, rt.isUnderlined());
                break;
        }
    }
    ppt.close();
}
Also used : HSLFTextRun(org.apache.poi.hslf.usermodel.HSLFTextRun) HSLFMasterSheet(org.apache.poi.hslf.usermodel.HSLFMasterSheet) HSLFTextParagraph(org.apache.poi.hslf.usermodel.HSLFTextParagraph) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) HSLFTitleMaster(org.apache.poi.hslf.usermodel.HSLFTitleMaster) 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