Search in sources :

Example 1 with XMLSlideShow

use of org.apache.poi.xslf.usermodel.XMLSlideShow in project poi by apache.

the class XSLFFileHandler method handleFile.

@Override
public void handleFile(InputStream stream, String path) throws Exception {
    XMLSlideShow slide = new XMLSlideShow(stream);
    XSLFSlideShow slideInner = new XSLFSlideShow(slide.getPackage());
    assertNotNull(slideInner.getPresentation());
    assertNotNull(slideInner.getSlideMasterReferences());
    assertNotNull(slideInner.getSlideReferences());
    new POIXMLDocumentHandler().handlePOIXMLDocument(slide);
    handleSlideShow(slide);
    slideInner.close();
    slide.close();
}
Also used : XMLSlideShow(org.apache.poi.xslf.usermodel.XMLSlideShow) XSLFSlideShow(org.apache.poi.xslf.usermodel.XSLFSlideShow)

Example 2 with XMLSlideShow

use of org.apache.poi.xslf.usermodel.XMLSlideShow 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 3 with XMLSlideShow

use of org.apache.poi.xslf.usermodel.XMLSlideShow in project poi by apache.

the class Step1 method main.

public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        System.out.println("Input file is required");
        return;
    }
    FileInputStream fis = new FileInputStream(args[0]);
    XMLSlideShow ppt = new XMLSlideShow(fis);
    fis.close();
    for (XSLFSlide slide : ppt.getSlides()) {
        System.out.println("Title: " + slide.getTitle());
        for (XSLFShape shape : slide.getShapes()) {
            if (shape instanceof XSLFTextShape) {
                XSLFTextShape tsh = (XSLFTextShape) shape;
                for (XSLFTextParagraph p : tsh) {
                    System.out.println("Paragraph level: " + p.getIndentLevel());
                    for (XSLFTextRun r : p) {
                        System.out.println(r.getRawText());
                        System.out.println("  bold: " + r.isBold());
                        System.out.println("  italic: " + r.isItalic());
                        System.out.println("  underline: " + r.isUnderlined());
                        System.out.println("  font.family: " + r.getFontFamily());
                        System.out.println("  font.size: " + r.getFontSize());
                        System.out.println("  font.color: " + r.getFontColor());
                    }
                }
            }
        }
    }
    ppt.close();
}
Also used : XSLFSlide(org.apache.poi.xslf.usermodel.XSLFSlide) XSLFTextParagraph(org.apache.poi.xslf.usermodel.XSLFTextParagraph) XMLSlideShow(org.apache.poi.xslf.usermodel.XMLSlideShow) XSLFTextShape(org.apache.poi.xslf.usermodel.XSLFTextShape) XSLFShape(org.apache.poi.xslf.usermodel.XSLFShape) FileInputStream(java.io.FileInputStream) XSLFTextRun(org.apache.poi.xslf.usermodel.XSLFTextRun)

Example 4 with XMLSlideShow

use of org.apache.poi.xslf.usermodel.XMLSlideShow in project poi by apache.

the class Step2 method main.

public static void main(String[] args) throws Exception {
    XMLSlideShow ppt = new XMLSlideShow();
    // first see what slide layouts are available by default
    System.out.println("Available slide layouts:");
    for (XSLFSlideMaster master : ppt.getSlideMasters()) {
        for (XSLFSlideLayout layout : master.getSlideLayouts()) {
            System.out.println(layout.getType());
        }
    }
    // blank slide
    /*XSLFSlide blankSlide =*/
    ppt.createSlide();
    XSLFSlideMaster defaultMaster = ppt.getSlideMasters().get(0);
    // title slide
    XSLFSlideLayout titleLayout = defaultMaster.getLayout(SlideLayout.TITLE);
    XSLFSlide slide1 = ppt.createSlide(titleLayout);
    XSLFTextShape title1 = slide1.getPlaceholder(0);
    title1.setText("First Title");
    // title and content
    XSLFSlideLayout titleBodyLayout = defaultMaster.getLayout(SlideLayout.TITLE_AND_CONTENT);
    XSLFSlide slide2 = ppt.createSlide(titleBodyLayout);
    XSLFTextShape title2 = slide2.getPlaceholder(0);
    title2.setText("Second Title");
    XSLFTextShape body2 = slide2.getPlaceholder(1);
    // unset any existing text
    body2.clearText();
    body2.addNewTextParagraph().addNewTextRun().setText("First paragraph");
    body2.addNewTextParagraph().addNewTextRun().setText("Second paragraph");
    body2.addNewTextParagraph().addNewTextRun().setText("Third paragraph");
    FileOutputStream out = new FileOutputStream("step2.pptx");
    ppt.write(out);
    out.close();
    ppt.close();
}
Also used : XSLFSlideMaster(org.apache.poi.xslf.usermodel.XSLFSlideMaster) XSLFSlide(org.apache.poi.xslf.usermodel.XSLFSlide) XMLSlideShow(org.apache.poi.xslf.usermodel.XMLSlideShow) XSLFTextShape(org.apache.poi.xslf.usermodel.XSLFTextShape) FileOutputStream(java.io.FileOutputStream) XSLFSlideLayout(org.apache.poi.xslf.usermodel.XSLFSlideLayout)

Example 5 with XMLSlideShow

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

Aggregations

XMLSlideShow (org.apache.poi.xslf.usermodel.XMLSlideShow)25 Test (org.junit.Test)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputStream (java.io.InputStream)6 Metacard (ddf.catalog.data.Metacard)5 XSLFSlide (org.apache.poi.xslf.usermodel.XSLFSlide)4 FileInputStream (java.io.FileInputStream)3 IOException (java.io.IOException)3 XSLFTextShape (org.apache.poi.xslf.usermodel.XSLFTextShape)3 XWPFDocument (org.apache.poi.xwpf.usermodel.XWPFDocument)3 Rectangle2D (java.awt.geom.Rectangle2D)2 FileOutputStream (java.io.FileOutputStream)2 Date (java.util.Date)2 HSLFSlideShow (org.apache.poi.hslf.usermodel.HSLFSlideShow)2 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)2 HWPFDocument (org.apache.poi.hwpf.HWPFDocument)2 OPCPackage (org.apache.poi.openxml4j.opc.OPCPackage)2 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)2 XSLFShape (org.apache.poi.xslf.usermodel.XSLFShape)2