/** * Adds a slide containing the metric's graph to the PowerPoint slide deck. The title is usually * the metric's name and is usually in camelCase format. This will be converted to individual, * capitalized words to the slide's title. The metric's data is used to determine the total count * across all of the metric's data, which is displayed at the bottom of the slide, under the * graph. * * @param ppt the PowerPoint slide deck to add this slide to * @param title the title for this slide * @param graph the metric's graph to be added to this slide * @param metricData the metric's data * @throws IOException * @throws MetricsGraphException */ private void createSlide(SlideShow ppt, String title, byte[] graph, MetricData metricData) throws IOException, MetricsGraphException { LOGGER.trace("ENTERING: createSlide"); if (LOGGER.isDebugEnabled()) { java.awt.Dimension pgsize = ppt.getPageSize(); int pgx = pgsize.width; // slide width (720) int pgy = pgsize.height; // slide height (540) LOGGER.debug("ppt page width = " + pgx); LOGGER.debug("ppt page height = " + pgy); } // Convert title, if it is in camelCase, to individual words with each word // starting with a capital letter String slideTitle = convertCamelCase(title); // String[] titleParts = StringUtils.splitByCharacterTypeCamelCase(title); // String slideTitle = ""; // for (String titlePart : titleParts) // { // slideTitle += titlePart + " "; // } // slideTitle = StringUtils.capitalize(slideTitle); Slide slide = ppt.createSlide(); // Add the title to the slide TextBox titleTextBox = slide.addTitle(); TextRun textRun = titleTextBox.getTextRun(); textRun.getRichTextRuns()[0].setFontSize(32); titleTextBox.setText(slideTitle); titleTextBox.setHorizontalAlignment(TextBox.AlignCenter); // Add the metric's graph to the slide int idx = ppt.addPicture(graph, Picture.PNG); Picture pict = new Picture(idx); // set graph's position and size in the slide // (Be sure to maintain aspect ratio for the image when specifying the // width and height. Refer to width and height values used in createGraph()) pict.setAnchor(new Rectangle(20, 100, 650, 325)); slide.addShape(pict); // If metric has a total count, add it under the graph on the slide if (metricData.hasTotalCount()) { TextBox totalCountTextBox = new TextBox(); textRun = totalCountTextBox.getTextRun(); textRun.getRichTextRuns()[0].setFontSize(14); totalCountTextBox.setText("Total Count: " + metricData.getTotalCount()); totalCountTextBox.setHorizontalAlignment(TextBox.AlignLeft); // x,y values determined relative to x,y of graph's anchor position // and the height of the graph totalCountTextBox.setAnchor(new Rectangle(20, 450, 250, 80)); slide.addShape(totalCountTextBox); } LOGGER.trace("EXITING: createSlide"); }
public void testSetParagraphStyles() throws Exception { SlideShow ppt = new SlideShow(); Slide slide = ppt.createSlide(); TextBox shape = new TextBox(); RichTextRun rt = shape.getTextRun().getRichTextRuns()[0]; shape.setText("Hello, World!\r" + "This should be\r" + "Multiline text"); rt.setFontSize(42); rt.setBullet(true); rt.setTextOffset(50); rt.setBulletOffset(0); rt.setBulletChar('\u263A'); slide.addShape(shape); assertEquals(42, rt.getFontSize()); assertEquals(true, rt.isBullet()); assertEquals(50, rt.getTextOffset()); assertEquals(0, rt.getBulletOffset()); assertEquals('\u263A', rt.getBulletChar()); shape.setAnchor(new java.awt.Rectangle(50, 50, 500, 300)); slide.addShape(shape); // serialize and read again ByteArrayOutputStream out = new ByteArrayOutputStream(); ppt.write(out); out.close(); ppt = new SlideShow(new ByteArrayInputStream(out.toByteArray())); slide = ppt.getSlides()[0]; shape = (TextBox) slide.getShapes()[0]; rt = shape.getTextRun().getRichTextRuns()[0]; assertEquals(42, rt.getFontSize()); assertEquals(true, rt.isBullet()); assertEquals(50, rt.getTextOffset()); assertEquals(0, rt.getBulletOffset()); assertEquals('\u263A', rt.getBulletChar()); }
public static void main(String[] args) throws Exception { SlideShow ss = new SlideShow(); Slide s1 = ss.createSlide(); TextBox title = s1.addTitle(); title.setText("サンプル文書"); int picIndex = ss.addPicture(new File("project-logo.jpg"), Picture.JPEG); Picture logo = new Picture(picIndex); s1.addShape(logo); ss.write(new FileOutputStream(new File("sample.ppt"))); }