-
-
Save adamloving/ff56d302edf4ebaa099f to your computer and use it in GitHub Desktop.
| 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); | |
| } | |
| } | |
| } | |
| } | |
| } |
Hi, thanks for the great sample.
Could please help me to get font name, of text of each slides?
@SaharNasiri I think this example will help you: http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/tutorial/Step1.java
thanks a lot
Hi Do you have reference for how to embed font inside .pptx file
Very helpful, really appreciate you sharing this.
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 of XSLFPictureShape type. Can you tell me how should I compare these XSLFPictureShape objects .
Thanks
To run
$ javac -cp ...and$ java -cp ...specifying jar files)