List of usage examples for org.apache.poi.xslf.usermodel XSLFTextShape getText
@Override
public String getText()
From source file:easyoffice.powerpoint.PPTMaker.java
private static void replaceContent(XSLFTextShape shape, SlideText data) { /*/* ww w .j a v a 2 s. c o m*/ Given a slide shape, replace it content with SlideText data */ String textInShape = shape.getText(); String newText = textInShape.replace(String.format(STRING_FORMAT, data.key), data.value); XSLFTextRun addedText = shape.setText(newText.replace("\r", "")); // not include break line addedText.setFontFamily(HSSFFont.FONT_ARIAL); addedText.setFontColor(Color.BLACK); }
From source file:easyoffice.powerpoint.PPTMaker.java
private static void processSlides(XMLSlideShow ppt) { ArrayList<Slide> replacementData = generateSlides(); XSLFSlide templateSlide = ppt.getSlides().get(TEMPLATE_SLIDE_INDEX); boolean somethingReplaced = false; for (Slide slide : replacementData) { XSLFSlide copiedSlide = copySlide(ppt, templateSlide); List<XSLFShape> slideShapes = copiedSlide.getShapes(); for (XSLFShape slideShape : slideShapes) { if (slideShape instanceof XSLFTextShape) { XSLFTextShape textShape = (XSLFTextShape) slideShape; for (SlideText slideText : slide.replacementData) { if (textShape.getText().contains(String.format(STRING_FORMAT, slideText.key))) { replaceContent(textShape, slideText); somethingReplaced = true; }//ww w . j av a 2s . co m } } } } if (!somethingReplaced) { System.out.println(Strings.NOTHING_REPLACED(TEMPLATE_SLIDE_INDEX)); System.exit(0); } }
From source file:mj.ocraptor.extraction.tika.parser.microsoft.ooxml.XSLFPowerPointExtractorDecorator.java
License:Apache License
private void extractContent(XSLFShape[] shapes, boolean skipPlaceholders, XHTMLContentHandler xhtml, String slideDesc) throws SAXException { for (XSLFShape sh : shapes) { if (sh instanceof XSLFTextShape) { XSLFTextShape txt = (XSLFTextShape) sh; Placeholder ph = txt.getTextType(); if (skipPlaceholders && ph != null) { continue; }/*from ww w . j a v a 2 s. com*/ xhtml.element("p", txt.getText()); } else if (sh instanceof XSLFGroupShape) { // recurse into groups of shapes XSLFGroupShape group = (XSLFGroupShape) sh; extractContent(group.getShapes(), skipPlaceholders, xhtml, slideDesc); } else if (sh instanceof XSLFTable) { XSLFTable tbl = (XSLFTable) sh; for (XSLFTableRow row : tbl) { List<XSLFTableCell> cells = row.getCells(); extractContent(cells.toArray(new XSLFTableCell[cells.size()]), skipPlaceholders, xhtml, slideDesc); } } else if (sh instanceof XSLFGraphicFrame) { XSLFGraphicFrame frame = (XSLFGraphicFrame) sh; XmlObject[] sp = frame.getXmlObject().selectPath( "declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' .//*/p:oleObj"); if (sp != null) { for (XmlObject emb : sp) { XmlObject relIDAtt = emb.selectAttribute(new QName( "http://schemas.openxmlformats.org/officeDocument/2006/relationships", "id")); if (relIDAtt != null) { String relID = relIDAtt.getDomNode().getNodeValue(); if (slideDesc != null) { relID = slideDesc + relID; } AttributesImpl attributes = new AttributesImpl(); attributes.addAttribute("", "class", "class", "CDATA", "embedded"); attributes.addAttribute("", "id", "id", "CDATA", relID); xhtml.startElement("div", attributes); xhtml.endElement("div"); } } } } else if (sh instanceof XSLFPictureShape) { if (!skipPlaceholders && (sh.getXmlObject() instanceof CTPicture)) { CTPicture ctPic = ((CTPicture) sh.getXmlObject()); if (ctPic.getBlipFill() != null && ctPic.getBlipFill().getBlip() != null) { String relID = ctPic.getBlipFill().getBlip().getEmbed(); if (relID != null) { if (slideDesc != null) { relID = slideDesc + relID; } AttributesImpl attributes = new AttributesImpl(); attributes.addAttribute("", "class", "class", "CDATA", "embedded"); attributes.addAttribute("", "id", "id", "CDATA", relID); xhtml.startElement("div", attributes); xhtml.endElement("div"); } } } } } }
From source file:poi.xslf.usermodel.DataExtraction.java
License:Apache License
public static void main(String args[]) throws Exception { if (args.length == 0) { System.out.println("Input file is required"); return;// w w w . j a v a 2 s. c o m } FileInputStream is = new FileInputStream(args[0]); XMLSlideShow ppt = new XMLSlideShow(is); is.close(); // Get the document's embedded files. List<PackagePart> embeds = ppt.getAllEmbedds(); for (PackagePart p : embeds) { String type = p.getContentType(); String name = p.getPartName().getName(); //typically file name InputStream pIs = p.getInputStream(); // make sense of the part data pIs.close(); } // Get the document's embedded files. List<XSLFPictureData> images = ppt.getAllPictures(); for (XSLFPictureData data : images) { PackagePart p = data.getPackagePart(); String type = p.getContentType(); String name = data.getFileName(); InputStream pIs = p.getInputStream(); // make sense of the image data pIs.close(); } Dimension pageSize = ppt.getPageSize(); // size of the canvas in points for (XSLFSlide slide : ppt.getSlides()) { for (XSLFShape shape : slide) { Rectangle2D anchor = shape.getAnchor(); // position on the canvas if (shape instanceof XSLFTextShape) { XSLFTextShape txShape = (XSLFTextShape) shape; System.out.println(txShape.getText()); } else if (shape instanceof XSLFPictureShape) { XSLFPictureShape pShape = (XSLFPictureShape) shape; XSLFPictureData pData = pShape.getPictureData(); System.out.println(pData.getFileName()); } else { System.out.println("Process me: " + shape.getClass()); } } } }