Search in sources :

Example 6 with HSLFSlideShow

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

the class LoadEmbedded method loadEmbedded.

public static void loadEmbedded(XSSFWorkbook workbook) throws IOException, InvalidFormatException, OpenXML4JException, XmlException {
    for (PackagePart pPart : workbook.getAllEmbedds()) {
        String contentType = pPart.getContentType();
        if (contentType.equals("application/vnd.ms-excel")) {
            // Excel Workbook - either binary or OpenXML
            HSSFWorkbook embeddedWorkbook = new HSSFWorkbook(pPart.getInputStream());
            embeddedWorkbook.close();
        } else if (contentType.equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) {
            // Excel Workbook - OpenXML file format
            XSSFWorkbook embeddedWorkbook = new XSSFWorkbook(pPart.getInputStream());
            embeddedWorkbook.close();
        } else if (contentType.equals("application/msword")) {
            // Word Document - binary (OLE2CDF) file format
            HWPFDocument document = new HWPFDocument(pPart.getInputStream());
            document.close();
        } else if (contentType.equals("application/vnd.openxmlformats-officedocument.wordprocessingml.document")) {
            // Word Document - OpenXML file format
            XWPFDocument document = new XWPFDocument(pPart.getInputStream());
            document.close();
        } else if (contentType.equals("application/vnd.ms-powerpoint")) {
            // PowerPoint Document - binary file format
            HSLFSlideShow slideShow = new HSLFSlideShow(pPart.getInputStream());
            slideShow.close();
        } else if (contentType.equals("application/vnd.openxmlformats-officedocument.presentationml.presentation")) {
            // PowerPoint Document - OpenXML file format
            XMLSlideShow slideShow = new XMLSlideShow(pPart.getInputStream());
            slideShow.close();
        } else {
            // Any other type of embedded object.
            System.out.println("Unknown Embedded Document: " + contentType);
            InputStream inputStream = pPart.getInputStream();
            inputStream.close();
        }
    }
}
Also used : HWPFDocument(org.apache.poi.hwpf.HWPFDocument) InputStream(java.io.InputStream) XMLSlideShow(org.apache.poi.xslf.usermodel.XMLSlideShow) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) XWPFDocument(org.apache.poi.xwpf.usermodel.XWPFDocument) PackagePart(org.apache.poi.openxml4j.opc.PackagePart) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 7 with HSLFSlideShow

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

the class EmbeddedObjects method main.

public static void main(String[] args) throws Exception {
    XSSFWorkbook workbook = new XSSFWorkbook(args[0]);
    for (PackagePart pPart : workbook.getAllEmbedds()) {
        String contentType = pPart.getContentType();
        InputStream is = pPart.getInputStream();
        Closeable document;
        if (contentType.equals("application/vnd.ms-excel")) {
            // Excel Workbook - either binary or OpenXML
            document = new HSSFWorkbook(is);
        } else if (contentType.equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) {
            // Excel Workbook - OpenXML file format
            document = new XSSFWorkbook(is);
        } else if (contentType.equals("application/msword")) {
            // Word Document - binary (OLE2CDF) file format
            document = new HWPFDocument(is);
        } else if (contentType.equals("application/vnd.openxmlformats-officedocument.wordprocessingml.document")) {
            // Word Document - OpenXML file format
            document = new XWPFDocument(is);
        } else if (contentType.equals("application/vnd.ms-powerpoint")) {
            // PowerPoint Document - binary file format
            document = new HSLFSlideShow(is);
        } else if (contentType.equals("application/vnd.openxmlformats-officedocument.presentationml.presentation")) {
            // PowerPoint Document - OpenXML file format
            document = new XMLSlideShow(is);
        } else {
            // Any other type of embedded object.
            document = is;
        }
        document.close();
        is.close();
    }
    workbook.close();
}
Also used : HWPFDocument(org.apache.poi.hwpf.HWPFDocument) InputStream(java.io.InputStream) Closeable(java.io.Closeable) XMLSlideShow(org.apache.poi.xslf.usermodel.XMLSlideShow) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) XWPFDocument(org.apache.poi.xwpf.usermodel.XWPFDocument) PackagePart(org.apache.poi.openxml4j.opc.PackagePart) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 8 with HSLFSlideShow

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

Example 9 with HSLFSlideShow

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

the class TestSlideMaster method testMasterAttributes.

/**
     * If a style attribute is not set ensure it is read from the master
     */
@Test
public void testMasterAttributes() throws Exception {
    HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
    List<HSLFSlide> slide = ppt.getSlides();
    assertEquals(3, slide.size());
    for (List<HSLFTextParagraph> tparas : slide.get(0).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) {
            HSLFTextRun rt = tpara.getTextRuns().get(0);
            assertEquals(0, tpara.getIndentLevel());
            assertEquals(32, rt.getFontSize(), 0);
            assertEquals("Arial", rt.getFontFamily());
            tpara = tparas.get(1);
            rt = tpara.getTextRuns().get(0);
            assertEquals(1, tpara.getIndentLevel());
            assertEquals(28, rt.getFontSize(), 0);
            assertEquals("Arial", rt.getFontFamily());
        }
    }
    for (List<HSLFTextParagraph> tparas : slide.get(1).getTextParagraphs()) {
        HSLFTextParagraph tpara = tparas.get(0);
        if (tpara.getRunType() == TextHeaderAtom.TITLE_TYPE) {
            HSLFTextRun rt = tpara.getTextRuns().get(0);
            assertEquals(48, rt.getFontSize(), 0);
            assertEquals(true, rt.isItalic());
            assertEquals("Georgia", rt.getFontFamily());
        } else if (tpara.getRunType() == TextHeaderAtom.BODY_TYPE) {
            HSLFTextRun rt;
            rt = tpara.getTextRuns().get(0);
            assertEquals(0, tpara.getIndentLevel());
            assertEquals(32, rt.getFontSize(), 0);
            assertEquals("Courier New", rt.getFontFamily());
        }
    }
    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)

Example 10 with HSLFSlideShow

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

the class TestSlideMaster method testSlideMaster.

/**
     * The reference ppt has two masters.
     * Check we can read their attributes.
     */
@Test
public void testSlideMaster() throws IOException {
    HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
    Environment env = ppt.getDocumentRecord().getEnvironment();
    List<HSLFSlideMaster> master = ppt.getSlideMasters();
    assertEquals(2, master.size());
    //character attributes
    assertEquals(40, master.get(0).getStyleAttribute(TextHeaderAtom.TITLE_TYPE, 0, "font.size", true).getValue());
    assertEquals(48, master.get(1).getStyleAttribute(TextHeaderAtom.TITLE_TYPE, 0, "font.size", true).getValue());
    int font1 = master.get(0).getStyleAttribute(TextHeaderAtom.TITLE_TYPE, 0, "font.index", true).getValue();
    int font2 = master.get(1).getStyleAttribute(TextHeaderAtom.TITLE_TYPE, 0, "font.index", true).getValue();
    assertEquals("Arial", env.getFontCollection().getFontWithId(font1));
    assertEquals("Georgia", env.getFontCollection().getFontWithId(font2));
    CharFlagsTextProp prop1 = (CharFlagsTextProp) master.get(0).getStyleAttribute(TextHeaderAtom.TITLE_TYPE, 0, "char_flags", true);
    assertEquals(false, prop1.getSubValue(CharFlagsTextProp.BOLD_IDX));
    assertEquals(false, prop1.getSubValue(CharFlagsTextProp.ITALIC_IDX));
    assertEquals(true, prop1.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
    CharFlagsTextProp prop2 = (CharFlagsTextProp) master.get(1).getStyleAttribute(TextHeaderAtom.TITLE_TYPE, 0, "char_flags", true);
    assertEquals(false, prop2.getSubValue(CharFlagsTextProp.BOLD_IDX));
    assertEquals(true, prop2.getSubValue(CharFlagsTextProp.ITALIC_IDX));
    assertEquals(false, prop2.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
    //now paragraph attributes
    assertEquals(0x266B, master.get(0).getStyleAttribute(TextHeaderAtom.BODY_TYPE, 0, "bullet.char", false).getValue());
    assertEquals(0x2022, master.get(1).getStyleAttribute(TextHeaderAtom.BODY_TYPE, 0, "bullet.char", false).getValue());
    int b1 = master.get(0).getStyleAttribute(TextHeaderAtom.BODY_TYPE, 0, "bullet.font", false).getValue();
    int b2 = master.get(1).getStyleAttribute(TextHeaderAtom.BODY_TYPE, 0, "bullet.font", false).getValue();
    assertEquals("Arial", env.getFontCollection().getFontWithId(b1));
    assertEquals("Georgia", env.getFontCollection().getFontWithId(b2));
    ppt.close();
}
Also used : Environment(org.apache.poi.hslf.record.Environment) HSLFSlideMaster(org.apache.poi.hslf.usermodel.HSLFSlideMaster) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) CharFlagsTextProp(org.apache.poi.hslf.model.textproperties.CharFlagsTextProp) 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