Attachment 'PPT2Text.java'

Download

   1 import java.io.FileInputStream;
   2 import java.io.FileOutputStream;
   3 import java.io.IOException;
   4 
   5 import org.apache.poi.hpsf.PropertySet;
   6 import org.apache.poi.poifs.eventfilesystem.POIFSReader;
   7 import org.apache.poi.poifs.eventfilesystem.POIFSReaderEvent;
   8 import org.apache.poi.poifs.eventfilesystem.POIFSReaderListener;
   9 import org.apache.poi.poifs.filesystem.DocumentInputStream;
  10 import org.apache.poi.util.LittleEndian;
  11 
  12 /**
  13  * @author sudhakar_koundinya at yahoo dot com
  14  */
  15 public class PPT2Text {
  16     public static void main(String[] args) throws IOException {
  17         final String filename = args[0];
  18         POIFSReader r = new POIFSReader();
  19 
  20         /* Register a listener for *all* documents. */
  21         r.registerListener(new MyPOIFSReaderListener());
  22         r.read(new FileInputStream(filename));
  23     }
  24 
  25     static class MyPOIFSReaderListener implements POIFSReaderListener {
  26 
  27         static int filename = 1;
  28 
  29         public void processPOIFSReaderEvent(POIFSReaderEvent event) {
  30             PropertySet ps = null;
  31 
  32             try {
  33 
  34                 DocumentInputStream dis = null;
  35 				dis = event.getStream();
  36                 
  37                 System.out.println("\n\n");
  38                 System.out.println(event.getPath() + event.getName());
  39                 
  40                 FileOutputStream fos =
  41                     new FileOutputStream("" + filename + ".txt");
  42 
  43                 byte btoWrite[] = new byte[dis.available()];
  44                 dis.read(btoWrite, 0, dis.available());
  45                 for (int i = 0; i < btoWrite.length - 20; i++) {
  46                     //System.out.println("Version:"+LittleEndian.getUnsignedByte(btoWrite,i+0));
  47                     //System.out.println("Instance:"+LittleEndian.getUShort(btoWrite,i+0));
  48                     //System.out.println("Type:"+LittleEndian.getUShort(btoWrite,i+2));
  49                     //System.out.println("Len:"+LittleEndian.getUInt(btoWrite,i+4));
  50 
  51                     long type = LittleEndian.getUShort(btoWrite, i + 2);
  52                     long size = LittleEndian.getUInt(btoWrite, i + 4);
  53                     if (type == 4008) {
  54                         fos.write(btoWrite, i + 4 + 1, (int) size + 3);
  55 
  56                     }
  57 
  58                 }
  59 
  60                 filename++;
  61             } catch (Exception ex) {
  62                 //System.out.println("No property set stream: \"" +event.getPath() +
  63                 //	event.getName() + "\"");
  64                 System.out.println(ex);
  65                 return;
  66             }
  67         }
  68     }
  69 }

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.

You are not allowed to attach a file to this page.