Presentation is loading. Please wait.

Presentation is loading. Please wait.

POI-HSLF Java API To Access Microsoft PowerPoint Format Files Yegor Kozlov yegor - apache - org.

Similar presentations


Presentation on theme: "POI-HSLF Java API To Access Microsoft PowerPoint Format Files Yegor Kozlov yegor - apache - org."— Presentation transcript:

1 POI-HSLF Java API To Access Microsoft PowerPoint Format Files Yegor Kozlov yegor - apache - org

2 What is HSLF? HorribleSLideshowFormat is the POI Project's pure Java implementation of the Powerpoint '97(-2007) file format. POI sub-project since 2005

3 HSLF in a Nutshell HSLF provides a way to read, create and modify MS PowerPoint presentations Pure Java API - you don't need PowerPoint to read and write *.ppt files Comprehensive support of PowerPoint objects –Rich text –Tables –Shapes –Pictures –Master slides Access to low level data structures

4 Note This presentation was created using POI HSLF The source code is available at http://people.apache.org/~yegor/apachecon_eu08/

5 HSLF in Action - 1 Data Extraction Text from slides and notes Images Shapes and their properties (type, position in the slide, color, font, etc.)

6 HSLF in Action - 2 Creating a simple presentation from scratch SlideShow ppt = new SlideShow(); Slide slide = ppt.createSlide(); TextBox box2 = new TextBox(); box2.setHorizontalAlignment(TextBox.AlignCenter); box2.setVerticalAlignment(TextBox.AnchorMiddle); box2.getTextRun().setText("Java Code"); box2.getFill().setForegroundColor(new Color(187, 224, 227)); box2.setLineColor(Color.black); box2.setLineWidth(0.75); box2.setAnchor(new Rectangle(66, 243, 170, 170)); slide.addShape(box2); TextBox box3 = new TextBox(); box3.setHorizontalAlignment(TextBox.AlignCenter); box3.setVerticalAlignment(TextBox.AnchorMiddle); box3.getTextRun().setText("*.ppt file"); box3.setLineWidth(0.75); box3.setLineColor(Color.black); box3.getFill().setForegroundColor(new Color(187, 224, 227)); box3.setAnchor(new Rectangle(473, 243, 170, 170)); slide.addShape(box3); AutoShape box4 = new AutoShape(ShapeTypes.Arrow); box4.getFill().setForegroundColor(new Color(187, 224, 227)); box4.setLineWidth(0.75); box4.setLineColor(Color.black); box4.setAnchor(new Rectangle(253, 288, 198, 85)); slide.addShape(box4); FileOutputStream out = new FileOutputStream("hslf-demo.ppt"); ppt.write(out); out.close();

7 Java Code*.ppt file

8 Wait, there is more! Rich text Tables Pictures (JPEG, PNG, BMP, WMF, PICT) Comprehensive formatting features

9 HSLF in Action - 3 PPGraphics2D: PowerPoint Graphics2D driver //bar chart data. The first value is the bar color, the second is the width Object[] def = new Object[]{ Color.yellow, new Integer(100), Color.green, new Integer(150), Color.gray, new Integer(75), Color.red, new Integer(200), }; SlideShow ppt = new SlideShow(); Slide slide = ppt.createSlide(); ShapeGroup group = new ShapeGroup(); //define position of the drawing in the slide Rectangle bounds = new java.awt.Rectangle(200, 100, 350, 300); group.setAnchor(bounds); slide.addShape(group); Graphics2D graphics = new PPGraphics2D(group); //draw a simple bar graph int x = bounds.x + 50, y = bounds.y + 50; graphics.setFont(new Font("Arial", Font.BOLD, 10)); for (int i = 0, idx = 1; i < def.length; i+=2, idx++) { graphics.setColor(Color.black); int width = ((Integer)def[i+1]).intValue(); graphics.drawString("Q" + idx, x-20, y+20); graphics.drawString(width + "%", x + width + 10, y + 20); graphics.setColor((Color)def[i]); graphics.fill(new Rectangle(x, y, width, 30)); y += 40; } graphics.setColor(Color.black); graphics.setFont(new Font("Arial", Font.BOLD, 14)); graphics.draw(bounds); graphics.drawString("Performance", x + 70, y + 40); FileOutputStream out = new FileOutputStream("hslf-demo.ppt"); ppt.write(out); out.close();

10 Q1100% Q2150% Q375% Q4200% Performance

11 HSLF Development Plans Support for more PowerPoint functionality Rendering slides into java.awt.Graphics2D –A way to export slides into images or other formats Integration with Apache FOP - Formatting Objects Processor –Transformation of XSL-FO into PPT –PPT2PDF transcoder

12 Questions? http://poi.apache.org/hslf/ http://people.apache.org/~yegor


Download ppt "POI-HSLF Java API To Access Microsoft PowerPoint Format Files Yegor Kozlov yegor - apache - org."

Similar presentations


Ads by Google