|
|
PowerML pro is a full-featured Java API for accessing data stored in PowerPoint presentations. PowerML pro also supports the XML conversion features offered by PowerML core.
See the PowerML pro Javadoc API documentation for API details.
The central class of the API is Presentation. In order to obtain an instance, first you have
to create a PresentationParser. Pass a java.io.InputStream instance
containing a PowerPoint file to the constructor, and finally use the parser's getPresentation
method.
// create a presentation parser for parsing presentation.ppt
PresentationParser parser = new PresentationParser(new FileInputStream("presentation.ppt"));
// get the Presentation instance
Presentation presentation = parser.getPresentation();
Now you can get access to various presentation properties like presentation size, summary etc.
// get presentation summary and print the presentation's author
Summary summary = presentation.getSummary();
System.out.println("Author: " + summary.getAuthor());
// print dimensions (in PowerPoint master units = 1"/576)
System.out.println("Presentation size: " + presentation.getWidth() + " x " + presentation.getHeight());
... or you can delve into the object graph containing a Java representation of the shapes, styles and layouts of the presentation.
// get first slide
ArrayList slides = presentation.getSlides();
if (slides.size() == 0) {
return; // presentation contains no slides
}
Slide slide = (Slide)slides.get(0);
// get first rectangle on the slide
ArrayList shapes = slide.getShapes();
SpRectangle rectangle = null;
if (shapes.size() > 0) {
Iterator shapeIterator = shapes.iterator();
while(shapeIterator.hasNext()) {
Shape shape = (Shape)shapeIterator.next();
if (shape.getTypeId() == ShapeTypes.RECTANGLE) {
rectangle = (SpRectangle)shape;
}
}
}
// if rectangle was found, print its position
if (rectangle != null) {
System.out.println("Rectangle found at (" + rectangle.getX() + ", " + rectangle.getY() + ")");
}
If you are interested in the XML conversion features, please refer to the PowerML core documentation.