List of usage examples for org.apache.poi.xslf.usermodel XMLSlideShow setPageSize
@Override public void setPageSize(Dimension pgSize)
From source file:info.opencards.util.playground.SlidesAndShapes.java
License:Apache License
public static void main(String[] args) throws Exception { XMLSlideShow ppt = new XMLSlideShow(); ppt.setPageSize(new Dimension(792, 612)); XSLFSlide slide1 = ppt.createSlide(); XSLFTextBox textBox = slide1.createTextBox(); XSLFTextRun r1 = textBox.addNewTextParagraph().addNewTextRun(); r1.setBold(true);/*from w w w . j a va 2 s . c o m*/ r1.setItalic(true); r1.setFontColor(Color.yellow); r1.setFontFamily("Arial"); r1.setFontSize(24); r1.setText("Apache"); XSLFTextRun r2 = textBox.addNewTextParagraph().addNewTextRun(); r2.setStrikethrough(true); r2.setUnderline(true); r2.setText("POI\u2122"); XSLFTextRun r3 = textBox.addNewTextParagraph().addNewTextRun(); r3.setFontFamily("Wingdings"); r3.setText(" Version 3.8"); textBox.setAnchor(new Rectangle(50, 50, 200, 100)); textBox.setLineColor(Color.black); textBox.setFillColor(Color.orange); XSLFAutoShape shape2 = slide1.createAutoShape(); shape2.setAnchor(new Rectangle(100, 100, 200, 200)); XSLFFreeformShape shape3 = slide1.createFreeform(); Rectangle rect = new Rectangle(150, 150, 300, 300); GeneralPath path = new GeneralPath(rect); path.append(new Ellipse2D.Double(200, 200, 100, 50), false); shape3.setPath(path); shape3.setAnchor(path.getBounds2D()); shape3.setLineColor(Color.black); shape3.setFillColor(Color.lightGray); XSLFSlide slide2 = ppt.createSlide(); XSLFGroupShape group = slide2.createGroup(); group.setAnchor(new Rectangle(0, 0, 792, 612)); group.setInteriorAnchor(new Rectangle(-10, -10, 20, 20)); XSLFAutoShape shape4 = group.createAutoShape(); shape4.setAnchor(new Rectangle(0, 0, 5, 5)); shape4.setLineWidth(5); shape4.setLineColor(Color.black); FileOutputStream out = new FileOutputStream("xslf-demo.pptx"); ppt.write(out); out.close(); }
From source file:org.quelea.data.powerpoint.PresentationSlide.java
License:Open Source License
/** * Create a new presentation slide./*from w ww . j a va 2s.com*/ * * @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); }