List of usage examples for org.apache.poi.xslf.usermodel XSLFSlide createPicture
@Override
public XSLFPictureShape createPicture(PictureData pictureData)
From source file:AddAudioToPptx.java
License:Apache License
public static void main(String[] args) throws Exception { URL video = new URL("http://archive.org/download/test-mpeg/test-mpeg.mpg"); // URL video = new URL("file:test-mpeg.mpg"); XMLSlideShow pptx = new XMLSlideShow(); // add video file String videoFileName = "lego_edsheeran.mp3"; PackagePartName partName = PackagingURIHelper.createPartName("/ppt/media/" + videoFileName); PackagePart part = pptx.getPackage().createPart(partName, "audio/mpeg"); OutputStream partOs = part.getOutputStream(); //InputStream fis = video.openStream(); FileInputStream fis = new FileInputStream(videoFileName); byte buf[] = new byte[1024]; for (int readBytes; (readBytes = fis.read(buf)) != -1; partOs.write(buf, 0, readBytes)) ;//from www . j a va 2 s . c om fis.close(); partOs.close(); XSLFSlide slide1 = pptx.createSlide(); byte[] picture = IOUtils.toByteArray(new FileInputStream("audio.png")); //adding the image to the presentation XSLFPictureData idx = pptx.addPicture(picture, XSLFPictureData.PictureType.PNG); //creating a slide with given picture on it XSLFPictureShape pv1 = slide1.createPicture(idx); //XSLFPictureShape pv1 = // addPreview(pptx, slide1, part, 5, 50, 80); addAudio(pptx, slide1, part, pv1, 5); addTimingInfo(slide1, pv1); //XSLFPictureShape pv2 = addPreview(pptx, slide1, part, 9, 50, 250); //addVideo(pptx, slide1, part, pv2, 9); //addTimingInfo(slide1, pv2); FileOutputStream fos = new FileOutputStream("pptx-with-audio.pptx"); pptx.write(fos); fos.close(); pptx.close(); }
From source file:AddAudioToPptx.java
License:Apache License
static XSLFPictureShape addPreview(XMLSlideShow pptx, XSLFSlide slide1, PackagePart videoPart, double seconds, int x, int y) throws IOException { // get preview after 5 sec. IContainer ic = IContainer.make();/*w w w .j av a 2s.c om*/ InputOutputStreamHandler iosh = new InputOutputStreamHandler(videoPart.getInputStream()); if (ic.open(iosh, IContainer.Type.READ, null) < 0) return null; IMediaReader mediaReader = ToolFactory.makeReader(ic); // stipulate that we want BufferedImages created in BGR 24bit color space mediaReader.setBufferedImageTypeToGenerate(BufferedImage.TYPE_3BYTE_BGR); ImageSnapListener isl = new ImageSnapListener(seconds); mediaReader.addListener(isl); // read out the contents of the media file and // dispatch events to the attached listener while (!isl.hasFired && mediaReader.readPacket() == null) ; mediaReader.close(); ic.close(); // add snapshot BufferedImage image1 = isl.image; ByteArrayOutputStream bos = new ByteArrayOutputStream(); ImageIO.write(image1, "jpeg", bos); XSLFPictureData snap = pptx.addPicture(bos.toByteArray(), PictureType.JPEG); XSLFPictureShape pic1 = slide1.createPicture(snap); pic1.setAnchor(new Rectangle(x, y, image1.getWidth(), image1.getHeight())); return pic1; }
From source file:com.hp.autonomy.frontend.reports.powerpoint.PowerPointServiceImpl.java
License:MIT License
/** * Internal implementation to add an image (a world map, though other image data is also fine) to a slide. * Preserves the original image's aspect ratio, leaving blank space below and to the sides of the image. * @param slide the slide to add to.//from www.jav a 2s.co m * @param anchor bounding rectangle to draw onto, in PowerPoint coordinates. * @param picture the picture data. * @param markers an array of markers to draw over the map. * @param polygons * @return the picture shape object added to the slide. */ private static XSLFPictureShape addMap(final XSLFSlide slide, final Rectangle2D.Double anchor, final XSLFPictureData picture, final Marker[] markers, final MapData.Polygon[] polygons) { double tgtW = anchor.getWidth(), tgtH = anchor.getHeight(); final Dimension size = picture.getImageDimension(); final double ratio = size.getWidth() / size.getHeight(); if (ratio > tgtW / tgtH) { // source image is wider than target, clip fixed width variable height tgtH = tgtW / ratio; } else { tgtW = tgtH * ratio; } final XSLFPictureShape canvas = slide.createPicture(picture); // Vertically align top, horizontally-align center final double offsetX = anchor.getMinX() + 0.5 * (anchor.getWidth() - tgtW), offsetY = anchor.getMinY(); canvas.setAnchor(new Rectangle2D.Double(offsetX, offsetY, tgtW, tgtH)); if (polygons != null) { for (MapData.Polygon polygon : polygons) { final Color color = Color.decode(polygon.getColor()); final double[][] shapes = polygon.getPoints(); // The ESRI spec version 1.2.1 from http://www.opengeospatial.org/standards/sfa has section 6.1.11.1, // which defines polygons as follows: /// A Polygon is a planar Surface defined by 1 exterior boundary and 0 or more interior boundaries. // Each interior boundary defines a hole in the Polygon. A Triangle is a polygon with 3 distinct, // non-collinear vertices and no interior boundary. /// The exterior boundary LinearRing defines the top? of the surface which is the side of the surface // from which the exterior boundary appears to traverse the boundary in a counter clockwise direction. // The interior LinearRings will have the opposite orientation, and appear as clockwise // when viewed from the top? // so it's even-odd winding (whereas the Path2D default is non-zero-winding). final Path2D.Double path = new Path2D.Double(Path2D.WIND_EVEN_ODD); for (final double[] points : shapes) { for (int ii = 0; ii < points.length; ii += 2) { final double x1 = offsetX + points[ii] * tgtW; final double y1 = offsetY + points[ii + 1] * tgtH; if (ii == 0) { path.moveTo(x1, y1); } else { path.lineTo(x1, y1); } } path.closePath(); } final XSLFFreeformShape freeform = slide.createFreeform(); freeform.setPath(path); freeform.setStrokeStyle(0.5); // There's a 0.5 alpha transparency on the stroke, and a 0.2 alpha transparency on the polygon fill. freeform.setLineColor(transparentColor(color, 128)); freeform.setFillColor(transparentColor(color, 51)); if (StringUtils.isNotEmpty(polygon.getText())) { final PackageRelationship rel = freeform.getSheet().getPackagePart().addRelationship( slide.getPackagePart().getPartName(), TargetMode.INTERNAL, XSLFRelation.SLIDE.getRelation()); // We create a hyperlink which links back to this slide; so we get hover-over-detail-text on the polygon final CTHyperlink link = ((CTShape) freeform.getXmlObject()).getNvSpPr().getCNvPr() .addNewHlinkClick(); link.setTooltip(polygon.getText()); link.setId(rel.getId()); link.setAction("ppaction://hlinksldjump"); } } } for (Marker marker : markers) { final Color color = Color.decode(marker.getColor()); final double centerX = offsetX + marker.getX() * tgtW; final double centerY = offsetY + marker.getY() * tgtH; if (marker.isCluster()) { final XSLFGroupShape group = slide.createGroup(); double halfMark = 10; double mark = halfMark * 2; double innerHalfMark = 7; double innerMark = innerHalfMark * 2; // align these so the middle is the latlng position final Rectangle2D.Double groupAnchor = new Rectangle2D.Double(centerX - halfMark, centerY - halfMark, mark, mark); group.setAnchor(groupAnchor); group.setInteriorAnchor(groupAnchor); final XSLFAutoShape shape = group.createAutoShape(); shape.setShapeType(ShapeType.ELLIPSE); final boolean fade = marker.isFade(); // There's a 0.3 alpha transparency (255 * 0.3 is 76) when a marker is faded out final int FADE_ALPHA = 76; shape.setFillColor(transparentColor(color, fade ? 47 : 154)); shape.setAnchor(groupAnchor); final XSLFAutoShape inner = group.createAutoShape(); inner.setFillColor(fade ? transparentColor(color, FADE_ALPHA) : color); inner.setLineWidth(0.1); inner.setLineColor(new Color((int) (color.getRed() * 0.9), (int) (color.getGreen() * 0.9), (int) (color.getBlue() * 0.9), fade ? FADE_ALPHA : 255)); inner.setShapeType(ShapeType.ELLIPSE); inner.setHorizontalCentered(true); inner.setWordWrap(false); inner.setVerticalAlignment(VerticalAlignment.MIDDLE); inner.clearText(); final XSLFTextParagraph para = inner.addNewTextParagraph(); para.setTextAlign(TextParagraph.TextAlign.CENTER); final XSLFTextRun text = para.addNewTextRun(); text.setFontSize(6.0); final Color fontColor = Color.decode(StringUtils.defaultString(marker.getFontColor(), "#000000")); text.setFontColor(fade ? transparentColor(fontColor, FADE_ALPHA) : fontColor); text.setText(marker.getText()); inner.setAnchor(new Rectangle2D.Double(centerX - innerHalfMark, centerY - innerHalfMark, innerMark, innerMark)); } else { final XSLFGroupShape group = slide.createGroup(); final XSLFFreeformShape shape = group.createFreeform(); shape.setHorizontalCentered(true); shape.setWordWrap(false); shape.setVerticalAlignment(VerticalAlignment.BOTTOM); shape.setLineWidth(0.5); shape.setLineColor(color.darker()); shape.setFillColor(transparentColor(color, 210)); final double halfMark = 8, mark = halfMark * 2, extension = 0.85, markerHeight = (0.5 + extension) * mark, angle = Math.asin(0.5 / extension) * 180 / Math.PI; // Set group position group.setAnchor( new Rectangle2D.Double(centerX - halfMark, centerY - markerHeight, mark, markerHeight)); group.setInteriorAnchor(new Rectangle2D.Double(0, 0, mark, markerHeight)); // Draw a semicircle and a triangle to represent the marker, pointing at the precise x,y location final Path2D.Double path = new Path2D.Double(); path.moveTo(halfMark, markerHeight); path.append(new Arc2D.Double(0, 0, mark, mark, -angle, 180 + angle + angle, Arc2D.OPEN), true); path.lineTo(halfMark, markerHeight); shape.setPath(path); shape.setAnchor(new Rectangle2D.Double(0, 0, mark, markerHeight)); final XSLFAutoShape disc = group.createAutoShape(); disc.setShapeType(ShapeType.DONUT); final double discRadius = 0.25 * mark; final double discDiameter = 2 * discRadius; disc.setAnchor(new Rectangle2D.Double(halfMark - discRadius, halfMark - discRadius, discDiameter, discDiameter)); disc.setFillColor(Color.WHITE); disc.setLineColor(Color.WHITE); if (StringUtils.isNotEmpty(marker.getText())) { final PackageRelationship rel = shape.getSheet().getPackagePart().addRelationship( slide.getPackagePart().getPartName(), TargetMode.INTERNAL, XSLFRelation.SLIDE.getRelation()); // We create a hyperlink which links back to this slide; so we get hover-over-detail-text on the marker // Annoyingly, you can't put a link on the group, just on the individual shapes. for (XSLFShape clickable : group.getShapes()) { final CTHyperlink link = ((CTShape) clickable.getXmlObject()).getNvSpPr().getCNvPr() .addNewHlinkClick(); link.setTooltip(marker.getText()); link.setId(rel.getId()); link.setAction("ppaction://hlinksldjump"); } } } } return canvas; }
From source file:com.hp.autonomy.frontend.reports.powerpoint.PowerPointServiceImpl.java
License:MIT License
/** * Internal implementation to add a list of documents to a presentation; either as a single slide or a series of slides. * @param imageSource the image source to convert images to data. * @param ppt the presentation to add to. * @param sl the slide to add to (can be null if pagination is enabled). * @param anchor bounding rectangle to draw onto, in PowerPoint coordinates. * @param paginate whether to render results as multiple slides if they don't fit on one slide. * @param data the documents to render.// www . j a v a 2s . c o m * @param results optional string to render into the top-left corner of the available space. * Will appear on each page if pagination is enabled. * @param sortBy optional string to render into the top-right corner of the available space. * Will appear on each page if pagination is enabled. */ private static void addList(final ImageSource imageSource, final XMLSlideShow ppt, XSLFSlide sl, final Rectangle2D.Double anchor, final boolean paginate, final ListData data, final String results, final String sortBy) { final double // How much space to leave at the left and right edge of the slide xMargin = 20, // How much space to leave at the top yMargin = 5, // Size of the icon iconWidth = 20, iconHeight = 24, // Find's thumbnail height is 97px by 55px, hardcoded in the CSS in .document-thumbnail thumbScale = 0.8, thumbW = 97 * thumbScale, thumbH = 55 * thumbScale, // Margin around the thumbnail thumbMargin = 4., // Space between list items listItemMargin = 5.; final Pattern highlightPattern = Pattern .compile("<HavenSearch-QueryText-Placeholder>(.*?)</HavenSearch-QueryText-Placeholder>"); double yCursor = yMargin + anchor.getMinY(), xCursor = xMargin + anchor.getMinX(); int docsOnPage = 0; final Document[] docs = data.getDocs(); for (int docIdx = 0; docIdx < docs.length; ++docIdx) { final Document doc = docs[docIdx]; if (sl == null) { sl = ppt.createSlide(); yCursor = yMargin + anchor.getMinY(); xCursor = xMargin + anchor.getMinX(); docsOnPage = 0; double yStep = 0; if (StringUtils.isNotBlank(results)) { final XSLFTextBox textBox = sl.createTextBox(); textBox.clearText(); final Rectangle2D.Double textBounds = new Rectangle2D.Double(xCursor, yCursor, Math.max(0, anchor.getMaxX() - xCursor - xMargin), 20); textBox.setAnchor(textBounds); addTextRun(textBox.addNewTextParagraph(), results, 12., Color.LIGHT_GRAY); yStep = textBox.getTextHeight(); } if (StringUtils.isNotBlank(sortBy)) { final XSLFTextBox sortByEl = sl.createTextBox(); sortByEl.clearText(); final XSLFTextParagraph sortByText = sortByEl.addNewTextParagraph(); sortByText.setTextAlign(TextParagraph.TextAlign.RIGHT); addTextRun(sortByText, sortBy, 12., Color.LIGHT_GRAY); sortByEl.setAnchor(new Rectangle2D.Double(xCursor, yCursor, Math.max(0, anchor.getMaxX() - xCursor - xMargin), 20)); yStep = Math.max(sortByEl.getTextHeight(), yStep); } if (yStep > 0) { yCursor += listItemMargin + yStep; } } XSLFAutoShape icon = null; if (data.isDrawIcons()) { icon = sl.createAutoShape(); icon.setShapeType(ShapeType.SNIP_1_RECT); icon.setAnchor(new Rectangle2D.Double(xCursor, yCursor + listItemMargin, iconWidth, iconHeight)); icon.setLineColor(Color.decode("#888888")); icon.setLineWidth(2.0); xCursor += iconWidth; } final XSLFTextBox listEl = sl.createTextBox(); listEl.clearText(); listEl.setAnchor(new Rectangle2D.Double(xCursor, yCursor, Math.max(0, anchor.getMaxX() - xCursor - xMargin), Math.max(0, anchor.getMaxY() - yCursor))); final XSLFTextParagraph titlePara = listEl.addNewTextParagraph(); addTextRun(titlePara, doc.getTitle(), data.getTitleFontSize(), Color.BLACK).setBold(true); if (StringUtils.isNotBlank(doc.getDate())) { final XSLFTextParagraph datePara = listEl.addNewTextParagraph(); datePara.setLeftMargin(5.); addTextRun(datePara, doc.getDate(), data.getDateFontSize(), Color.GRAY).setItalic(true); } if (StringUtils.isNotBlank(doc.getRef())) { addTextRun(listEl.addNewTextParagraph(), doc.getRef(), data.getRefFontSize(), Color.GRAY); } final double thumbnailOffset = listEl.getTextHeight(); final XSLFTextParagraph contentPara = listEl.addNewTextParagraph(); Rectangle2D.Double pictureAnchor = null; XSLFPictureData pictureData = null; if (StringUtils.isNotBlank(doc.getThumbnail())) { try { // Picture reuse is automatic pictureData = addPictureData(imageSource, ppt, doc.getThumbnail()); // We reserve space for the picture, but we don't actually add it yet. // The reason is we may have to remove it later if it doesn't fit; but due to a quirk of OpenOffice, // deleting the picture shape removes the pictureData as well; which is a problem since the // pictureData can be shared between multiple pictures. pictureAnchor = new Rectangle2D.Double(xCursor, yCursor + thumbnailOffset + thumbMargin, thumbW, thumbH); // If there is enough horizontal space, put the text summary to the right of the thumbnail image, // otherwise put it under the thumbnail, if (listEl.getAnchor().getWidth() > 2.5 * thumbW) { contentPara.setLeftMargin(thumbW); } else { contentPara.addLineBreak().setFontSize(thumbH); } } catch (RuntimeException e) { // if there's any errors, we'll just ignore the image } } final String rawSummary = doc.getSummary(); if (StringUtils.isNotBlank(rawSummary)) { // HTML treats newlines and multiple whitespace as a single whitespace. final String summary = rawSummary.replaceAll("\\s+", " "); final Matcher matcher = highlightPattern.matcher(summary); int idx = 0; while (matcher.find()) { final int start = matcher.start(); if (idx < start) { addTextRun(contentPara, summary.substring(idx, start), data.getSummaryFontSize(), Color.DARK_GRAY); } addTextRun(contentPara, matcher.group(1), data.getSummaryFontSize(), Color.DARK_GRAY) .setBold(true); idx = matcher.end(); } if (idx < summary.length()) { addTextRun(contentPara, summary.substring(idx), data.getSummaryFontSize(), Color.DARK_GRAY); } } double elHeight = Math.max(listEl.getTextHeight(), iconHeight); if (pictureAnchor != null) { elHeight = Math.max(elHeight, pictureAnchor.getMaxY() - yCursor); } yCursor += elHeight; xCursor = xMargin + anchor.getMinX(); docsOnPage++; if (yCursor > anchor.getMaxY()) { if (docsOnPage > 1) { // If we drew more than one list element on this page; and we exceeded the available space, // delete the last element's shapes and redraw it on the next page. // We don't have to remove the picture since we never added it. sl.removeShape(listEl); if (icon != null) { sl.removeShape(icon); } --docIdx; } else if (pictureAnchor != null) { // We've confirmed we need the picture, add it. sl.createPicture(pictureData).setAnchor(pictureAnchor); } sl = null; if (!paginate) { break; } } else { yCursor += listItemMargin; if (pictureAnchor != null) { // We've confirmed we need the picture, add it. sl.createPicture(pictureData).setAnchor(pictureAnchor); } } } }
From source file:org.maptalks.poi.animation.TestXSLFAnimationGroup.java
License:Apache License
@Test public void testAnimationGroup() throws Exception { XMLSlideShow pptx = new XMLSlideShow(); XSLFSlide slide = pptx.createSlide(); Dimension pageSize = pptx.getPageSize(); // Rectangle2D rectangle = new Rectangle2D.Double(0,0,pageSize.getWidth(),pageSize.getHeight()); Rectangle rectangle = new java.awt.Rectangle(0, 0, (int) pageSize.getWidth(), (int) pageSize.getHeight()); List<XSLFAnimationType> animationTypes = new ArrayList<XSLFAnimationType>(); XSLFAnimation animation = new XSLFAnimation(); String[] directions = new String[5]; directions[0] = MoveDirection.BOTTOM; directions[1] = MoveDirection.LEFT;//from w w w . ja va 2 s . c o m directions[2] = MoveDirection.TOP; directions[3] = MoveDirection.RIGHT; directions[4] = MoveDirection.BOTTOM; String pathStr = this.getClass().getResource("/images").getPath(); String nodeType = "clickEffect"; for (int i = 0; i < 3; i++) { String fileName = pathStr + "/" + (i + 1) + ".png"; File downloadeFile = new File(fileName); BufferedInputStream in = new BufferedInputStream(new FileInputStream(downloadeFile)); ByteArrayOutputStream out = new ByteArrayOutputStream(1024); int size = 0; byte[] temp = new byte[1024]; while ((size = in.read(temp)) != -1) { out.write(temp, 0, size); } in.close(); byte[] content = out.toByteArray(); XSLFPictureData pictureData = pptx.addPicture(content, org.apache.poi.sl.usermodel.PictureData.PictureType.PNG); XSLFPictureShape picShape = slide.createPicture(pictureData); picShape.setAnchor(rectangle); picShape.setLineWidth(0); if (i > 1) { nodeType = "afterEffect"; XSLFAnimationType animationType = new FlyIn(picShape, directions[i], nodeType); animationTypes.get(1).addChild(animationType); } else { XSLFAnimationType animationType = new FlyIn(picShape, directions[i], nodeType); animationTypes.add(animationType); } } animation.addAnimationToSlide(slide, animationTypes); FileOutputStream out = new FileOutputStream("d:\\group.pptx"); // FileOutputStream out = new FileOutputStream(pathStr+"/group.pptx"); pptx.write(out); out.close(); }
From source file:org.maptalks.poi.animation.TestXSLFAnimationShape.java
License:Apache License
@Test public void testAnimationSlide() throws Exception { XMLSlideShow pptx = new XMLSlideShow(); XSLFSlide slide = pptx.createSlide(); Dimension pageSize = pptx.getPageSize(); // Rectangle2D rectangle = new Rectangle2D.Double(0,0,pageSize.getWidth(),pageSize.getHeight()); Rectangle rectangle = new java.awt.Rectangle(0, 0, (int) pageSize.getWidth(), (int) pageSize.getHeight()); List<XSLFAnimationType> animationTypes = new ArrayList<XSLFAnimationType>(); XSLFAnimation animation = new XSLFAnimation(); String[] directions = new String[5]; directions[0] = MoveDirection.BOTTOM; directions[1] = MoveDirection.LEFT;/* w w w.ja v a 2 s. co m*/ directions[2] = MoveDirection.TOP; directions[3] = MoveDirection.RIGHT; directions[4] = MoveDirection.BOTTOM; String pathStr = this.getClass().getResource("/images").getPath(); for (int i = 0; i < 3; i++) { String fileName = pathStr + "/" + (i + 1) + ".png"; File downloadeFile = new File(fileName); BufferedInputStream in = new BufferedInputStream(new FileInputStream(downloadeFile)); ByteArrayOutputStream out = new ByteArrayOutputStream(1024); int size = 0; byte[] temp = new byte[1024]; while ((size = in.read(temp)) != -1) { out.write(temp, 0, size); } in.close(); byte[] content = out.toByteArray(); XSLFPictureData pictureData = pptx.addPicture(content, org.apache.poi.sl.usermodel.PictureData.PictureType.PNG); XSLFPictureShape picShape = slide.createPicture(pictureData); picShape.setAnchor(rectangle); picShape.setLineWidth(0); XSLFAnimationType animationType = new FlyIn(picShape, directions[i]); animationTypes.add(animationType); XSLFAnimationType animationOutType = new FlyOut(picShape, directions[i]); animationTypes.add(animationOutType); } slide = animation.addAnimationToSlide(slide, animationTypes); FileOutputStream out = new FileOutputStream("d:\\temp.pptx"); // FileOutputStream out = new FileOutputStream(pathStr+"/temp.pptx"); pptx.write(out); out.close(); }
From source file:org.maptalks.poi.animation.TestZoomIn.java
License:Apache License
@Test public void testAnimationSlide() throws Exception { XMLSlideShow pptx = new XMLSlideShow(); XSLFSlide slide = pptx.createSlide(); Dimension pageSize = pptx.getPageSize(); Rectangle rectangle = new java.awt.Rectangle(0, 0, (int) pageSize.getWidth(), (int) pageSize.getHeight()); // Rectangle2D rectangle = new Rectangle2D.Double(); List<XSLFAnimationType> animationTypes = new ArrayList<XSLFAnimationType>(); XSLFAnimation animation = new XSLFAnimation(); String[] directions = new String[5]; directions[0] = MoveDirection.BOTTOM; directions[1] = MoveDirection.LEFT;// www . ja v a 2 s . co m directions[2] = MoveDirection.TOP; directions[3] = MoveDirection.RIGHT; directions[4] = MoveDirection.BOTTOM; String pathStr = this.getClass().getResource("/images").getPath(); for (int i = 0; i < 3; i++) { String fileName = pathStr + "/" + (i + 1) + ".png"; File downloadeFile = new File(fileName); BufferedInputStream in = new BufferedInputStream(new FileInputStream(downloadeFile)); ByteArrayOutputStream out = new ByteArrayOutputStream(1024); int size = 0; byte[] temp = new byte[1024]; while ((size = in.read(temp)) != -1) { out.write(temp, 0, size); } in.close(); byte[] content = out.toByteArray(); XSLFPictureData pictureData = pptx.addPicture(content, org.apache.poi.sl.usermodel.PictureData.PictureType.PNG); XSLFPictureShape picShape = slide.createPicture(pictureData); picShape.setAnchor(rectangle); picShape.setLineWidth(0); XSLFAnimationType animationType = new ZoomIn(picShape, directions[i]); animationTypes.add(animationType); XSLFAnimationType animationOutType = new FlyOut(picShape, directions[i]); animationTypes.add(animationOutType); } slide = animation.addAnimationToSlide(slide, animationTypes); FileOutputStream out = new FileOutputStream("d:\\zoomin.pptx"); // FileOutputStream out = new FileOutputStream(pathStr+"/zoomin.pptx"); pptx.write(out); out.close(); }
From source file:org.maptalks.poi.animation.TestZoomOut.java
License:Apache License
@Test public void testAnimationSlide() throws Exception { XMLSlideShow pptx = new XMLSlideShow(); XSLFSlide slide = pptx.createSlide(); Dimension pageSize = pptx.getPageSize(); // Rectangle2D rectangle = new Rectangle2D.Double(0,0,pageSize.getWidth(),pageSize.getHeight()); Rectangle rectangle = new java.awt.Rectangle(0, 0, (int) pageSize.getWidth(), (int) pageSize.getHeight()); List<XSLFAnimationType> animationTypes = new ArrayList<XSLFAnimationType>(); XSLFAnimation animation = new XSLFAnimation(); String[] directions = new String[5]; directions[0] = MoveDirection.BOTTOM; directions[1] = MoveDirection.LEFT;/*w w w . j a va 2 s.c o m*/ directions[2] = MoveDirection.TOP; directions[3] = MoveDirection.RIGHT; directions[4] = MoveDirection.BOTTOM; String pathStr = this.getClass().getResource("/images").getPath(); for (int i = 0; i < 3; i++) { String fileName = pathStr + "/" + (i + 1) + ".png"; File downloadeFile = new File(fileName); BufferedInputStream in = new BufferedInputStream(new FileInputStream(downloadeFile)); ByteArrayOutputStream out = new ByteArrayOutputStream(1024); int size = 0; byte[] temp = new byte[1024]; while ((size = in.read(temp)) != -1) { out.write(temp, 0, size); } in.close(); byte[] content = out.toByteArray(); XSLFPictureData pictureData = pptx.addPicture(content, org.apache.poi.sl.usermodel.PictureData.PictureType.PNG); XSLFPictureShape picShape = slide.createPicture(pictureData); picShape.setAnchor(rectangle); picShape.setLineWidth(0); XSLFAnimationType animationType = new ZoomIn(picShape, directions[i]); animationTypes.add(animationType); XSLFAnimationType animationOutType = new ZoomOut(picShape, directions[i]); animationTypes.add(animationOutType); } slide = animation.addAnimationToSlide(slide, animationTypes); FileOutputStream out = new FileOutputStream("d:\\zoomout.pptx"); // FileOutputStream out = new FileOutputStream(pathStr+"/zoomout.pptx"); pptx.write(out); out.close(); }
From source file:poi.xslf.usermodel.Tutorial5.java
License:Apache License
public static void main(String[] args) throws IOException { XMLSlideShow ppt = new XMLSlideShow(); XSLFSlide slide = ppt.createSlide(); File img = new File(System.getProperty("POI.testdata.path"), "slideshow/clock.jpg"); byte[] data = IOUtils.toByteArray(new FileInputStream(img)); int pictureIndex = ppt.addPicture(data, XSLFPictureData.PICTURE_TYPE_PNG); XSLFPictureShape shape = slide.createPicture(pictureIndex); FileOutputStream out = new FileOutputStream("images.pptx"); ppt.write(out);//www. j a va 2s . c om out.close(); }