List of usage examples for org.apache.poi.xslf.usermodel XMLSlideShow getPageSize
@Override
public Dimension getPageSize()
From source file:com.github.codeurjc.slidesconverter.PowerPointToHTML.java
License:Apache License
public void convert() throws IOException { InputStream fis = Files.newInputStream(pptxFile); XMLSlideShow pptx = new XMLSlideShow(fis); fis.close();//from w w w . ja v a 2 s .c om InputStream is = Files.newInputStream(pptFile); HSLFSlideShow ppt = new HSLFSlideShow(is); is.close(); width = pptx.getPageSize().getWidth(); height = pptx.getPageSize().getHeight(); out = new PrintWriter(Files.newOutputStream(htmlFile)); out.println("<!DOCTYPE html>"); out.println("<html><body>"); out.println("<h1>" + this.mainTitleNumber + " " + mainTitle + "</h1>"); out.println("<h2>" + this.slidesContext + "</h2>"); List<Section> sections = calculateSections(pptx, ppt); generateTOC(sections); generateSlidesContent(pptx, ppt); pptx.close(); ppt.close(); out.close(); }
From source file:com.hp.autonomy.frontend.reports.powerpoint.PowerPointServiceImpl.java
License:MIT License
/** * Convert provided anchor points from fractional units (0-1 range) to PowerPoint coordinates. * @param ppt the PowerPoint presentation to use. * @param anchor the anchor in fractional (0-1) units. * @return bounding rectangle in PowerPoint coordinates. *//* ww w . j a va2 s . com*/ private static Rectangle2D.Double createPageAnchor(final XMLSlideShow ppt, final Anchor anchor) { final Dimension pageSize = ppt.getPageSize(); final double availW = pageSize.getWidth(); final double availH = pageSize.getHeight(); return new Rectangle2D.Double(availW * anchor.getX(), availH * anchor.getY(), availW * anchor.getWidth(), availH * anchor.getHeight()); }
From source file:com.linksinnovation.elearning.utils.ppt2pdf.Ppt2Pdf.java
public static void convert(FileInputStream inputStream, FileOutputStream out) throws IOException, DocumentException { XMLSlideShow ppt = new XMLSlideShow(inputStream); inputStream.close();/*from w w w . j a v a2 s . c om*/ Dimension pgsize = ppt.getPageSize(); Document document = new Document(); PdfWriter pdfWriter = PdfWriter.getInstance(document, out); document.setPageSize(new Rectangle((float) pgsize.getWidth(), (float) pgsize.getHeight())); document.open(); for (XSLFSlide slide : ppt.getSlides()) { System.out.println(pgsize.getWidth() + " " + pgsize.getHeight()); PdfGraphics2D graphics = (PdfGraphics2D) pdfWriter.getDirectContent() .createGraphics((float) pgsize.getWidth(), (float) pgsize.getHeight()); slide.draw(graphics); graphics.dispose(); document.newPage(); } document.close(); }
From source file:ddf.catalog.transformer.input.pptx.PptxInputTransformer.java
License:Open Source License
/** * If the slide show doesn't contain any slides, then return null. Otherwise, return jpeg * image data of the first slide in the deck. * * @param slideShow// www . j a va 2s . c om * @return jpeg thumbnail or null if thumbnail can't be created * @throws IOException */ private byte[] generatePptxThumbnail(XMLSlideShow slideShow) throws IOException { if (slideShow.getSlides().isEmpty()) { LOGGER.debug("the powerpoint file does not contain any slides, skipping thumbnail generation"); return null; } Dimension pgsize = slideShow.getPageSize(); int largestDimension = (int) Math.max(pgsize.getHeight(), pgsize.getWidth()); float scalingFactor = IMAGE_HEIGHTWIDTH / largestDimension; int scaledHeight = (int) (pgsize.getHeight() * scalingFactor); int scaledWidth = (int) (pgsize.getWidth() * scalingFactor); BufferedImage img = new BufferedImage(scaledWidth, scaledHeight, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = img.createGraphics(); try { graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); graphics.scale(scalingFactor, scalingFactor); slideShow.getSlides().get(0).draw(graphics); try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { ImageIOUtil.writeImage(img, FORMAT_NAME, outputStream, RESOLUTION_DPI, IMAGE_QUALITY); return outputStream.toByteArray(); } } catch (RuntimeException e) { if (e.getCause() instanceof javax.imageio.IIOException) { LOGGER.debug("unable to generate thumbnail for PPTX file", e); } else { throw e; } } finally { graphics.dispose(); } return null; }
From source file:openslide.module.webserver.PPTX2SVG.java
License:Apache License
/** * parse file to svg document//from w ww. j a v a 2s . c o m * @param file_name -required- {string} fullpath file * @return slide_list * @throws Exception */ public static ArrayList<String> parse(String file_name) throws Exception { String file = file_name; ArrayList<String> slide_list = new ArrayList<String>(); System.out.println("Processing " + file); // read the .pptx file XMLSlideShow ppt = new XMLSlideShow(OPCPackage.open(file)); Dimension pgsize = ppt.getPageSize(); // convert each slide into a .svg file XSLFSlide[] slide = ppt.getSlides(); for (int i = 0; i < slide.length; i++) { // Create initial SVG DOM DOMImplementation domImpl = SVGDOMImplementation.getDOMImplementation(); Document doc = domImpl.createDocument("http://www.w3.org/2000/svg", "svg", null); //Use Batik SVG Graphics2D driver SVGGraphics2D graphics = new SVGGraphics2D(doc); graphics.setRenderingHint(XSLFRenderingHint.IMAGE_RENDERER, new WMFImageRender()); graphics.setSVGCanvasSize(pgsize); String title = slide[i].getTitle(); System.out.println("Rendering slide " + (i + 1) + (title == null ? "" : ": " + title)); // draw stuff. All the heavy-lifting happens here slide[i].draw(graphics); // save the result. int sep = file.lastIndexOf("."); String fname = file.substring(0, sep == -1 ? file.length() : sep) + "-" + (i + 1) + ".svg"; slide_list.add(fname); OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(fname), "UTF-8"); DOMSource domSource = new DOMSource(graphics.getRoot()); StreamResult streamResult = new StreamResult(out); TransformerFactory tf = TransformerFactory.newInstance(); Transformer serializer = tf.newTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); serializer.transform(domSource, streamResult); out.flush(); out.close(); } System.out.println("Done"); return slide_list; }
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. j a v a 2 s . c om 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;//from 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;/*from ww w.j ava 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;/*from ww w . j a v a2 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:org.quelea.data.powerpoint.PresentationSlide.java
License:Open Source License
/** * Create a new presentation slide.//from ww w. ja v a2 s . c o m * * @param slide the underlying apache POI slide. */ public PresentationSlide(XSLFSlide slide, int numSlide) { org.apache.poi.xslf.usermodel.XMLSlideShow slideshow = slide.getSlideShow(); if (Math.abs(slideshow.getPageSize().getHeight() - HEIGHT) > 0.1) { int adjustHeight = HEIGHT; int adjustWidth = (int) ((adjustHeight / slideshow.getPageSize().getHeight()) * slideshow.getPageSize().getWidth()); scaleWidth = (double) adjustWidth / slideshow.getPageSize().getWidth(); scaleHeight = (double) adjustHeight / slideshow.getPageSize().getHeight(); slideshow.setPageSize(new Dimension(adjustWidth, adjustHeight)); } BufferedImage originalImage = new BufferedImage((int) slideshow.getPageSize().getWidth(), (int) slideshow.getPageSize().getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = originalImage.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); try { g2.setTransform(AffineTransform.getScaleInstance(scaleWidth, scaleHeight)); slide.draw(g2); } catch (NullPointerException ex) { if (QueleaProperties.get().getUsePP()) { LOGGER.log(Level.INFO, "Couldn't use library to generate thumbnail, using default"); draw(g2, originalImage.getWidth(), originalImage.getHeight(), numSlide); } else { throw ex; } } image = new WritableImage(originalImage.getWidth(), originalImage.getHeight()); SwingFXUtils.toFXImage(originalImage, image); }