poi-hslf java api to access microsoft powerpoint format files yegor kozlov yegor - apache - org

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

Upload: leonard-thomas

Post on 18-Jan-2016

212 views

Category:

Documents


0 download

TRANSCRIPT

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

POI-HSLF

Java API To Access Microsoft PowerPoint Format Files

Yegor Kozlovyegor - apache - org

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

What is HSLF?

• HorribleSLideshowFormat is the POI Project's pure Java implementation of the Powerpoint '97(-2007) file format.

• POI sub-project since 2005

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

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

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

Note

This presentation was created using POI HSLF

The source code is available athttp://people.apache.org/~yegor/apachecon_eu08/

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

HSLF in Action - 1Data Extraction

• Text from slides and notes

• Images

• Shapes and their properties (type, position in the slide, color, font, etc.)

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

HSLF in Action - 2Creating 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();

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

Java Code *.ppt file

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

Wait, there is more!

• Rich text

• Tables

• Pictures (JPEG, PNG, BMP, WMF, PICT)

• Comprehensive formatting features

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

HSLF in Action - 3PPGraphics2D: 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();

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

Q1 100%

Q2 150%

Q3 75%

Q4 200%

Performance

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

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

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

Questions?

http://poi.apache.org/hslf/

http://people.apache.org/~yegor