Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.apache.poi.hslf.extractor;
- import java.io.FileInputStream;
- import java.util.List;
- import org.apache.poi.hslf.usermodel.HSLFShape;
- import org.apache.poi.hslf.usermodel.HSLFShapeContainer;
- import org.apache.poi.hslf.usermodel.HSLFSlide;
- import org.apache.poi.hslf.usermodel.HSLFSlideShow;
- import org.apache.poi.hslf.usermodel.HSLFTextParagraph;
- import org.apache.poi.hslf.usermodel.HSLFTextRun;
- import org.apache.poi.hslf.usermodel.HSLFTextShape;
- import org.apache.poi.sl.usermodel.TextParagraph.BulletStyle;
- import org.junit.Test;
- // sample for thread:
- // http://apache-poi.1045710.n5.nabble.com/ANNOUNCE-Apache-POI-3-13-beta1-released-tt5719469.html#a5719837
- public class TestTeresa {
- @Test
- public void doit() throws Exception {
- FileInputStream fis = new FileInputStream("6_contingency_tables.ppt");
- HSLFSlideShow ppt = new HSLFSlideShow(fis);
- fis.close();
- StringBuilder sb = new StringBuilder();
- List<HSLFSlide> slides = ppt.getSlides();
- handleContainer(slides.get(1), sb);
- sb.append("---\n");
- handleContainer(slides.get(2), sb);
- sb.append("---\n");
- System.out.println(sb);
- }
- void handleContainer(HSLFShapeContainer sc, StringBuilder sb) {
- for (HSLFShape s : sc) {
- if (s instanceof HSLFTextShape) {
- HSLFTextShape ts = (HSLFTextShape)s;
- for (HSLFTextParagraph p : ts.getTextParagraphs()) {
- for (int i=0; i<p.getIndentLevel(); i++) {
- sb.append(" ");
- }
- BulletStyle bs = p.getBulletStyle();
- if (bs != null) {
- sb.append("* ");
- }
- for (HSLFTextRun r : p.getTextRuns()) {
- sb.append(r.getRawText());
- }
- sb.append("\n");
- }
- } else if (s instanceof HSLFShapeContainer) {
- handleContainer((HSLFShapeContainer)s, sb);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment