Created
March 25, 2015 21:21
-
-
Save adamloving/ff56d302edf4ebaa099f to your computer and use it in GitHub Desktop.
Read PowerPoint ppt pptx using Apache Poi in java!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import org.apache.poi.xslf.usermodel.XMLSlideShow; | |
import org.apache.poi.POIXMLProperties.*; | |
import org.apache.poi.xslf.usermodel.*; | |
public class HelloPoi { | |
public static void main(String[] args) { | |
String fileName; | |
if (args.length > 0) { | |
fileName = args[0]; | |
} else { | |
System.out.println("No file name specified."); | |
return; | |
} | |
FileInputStream inputStream; | |
try { | |
inputStream = new FileInputStream(fileName); | |
} catch (FileNotFoundException e) { | |
e.printStackTrace(); | |
return; | |
} | |
XMLSlideShow ppt; | |
try { | |
ppt = new XMLSlideShow(inputStream); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
return; | |
} | |
readPPT(ppt); | |
} | |
public static void readPPT(XMLSlideShow ppt) { | |
CoreProperties props = ppt.getProperties().getCoreProperties(); | |
String title = props.getTitle(); | |
System.out.println("Title: " + title); | |
for (XSLFSlide slide: ppt.getSlides()) { | |
System.out.println("Starting slide..."); | |
XSLFShape[] shapes = slide.getShapes(); | |
for (XSLFShape shape: shapes) { | |
if (shape instanceof XSLFTextShape) { | |
XSLFTextShape textShape = (XSLFTextShape)shape; | |
String text = textShape.getText(); | |
System.out.println("Text: " + text); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks adam for writing this & showing sample code to work with apache poi ppt files.
I am right now working on writing simple prog to compare two ppt files . I have used apache poi & was able to fetch shapes of slide using
getShapes()
. Now since my ppt contains images , shape is ofXSLFPictureShape
type. Can you tell me how should I compare theseXSLFPictureShape
objects .Thanks