dcsimg
Powerpoint to text
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   sudhakar_chavali
Posted On:   Thursday, August 12, 2004 06:21 AM

Hello all, As I don't know how to share my codes here, I am placing this as question. The following code converts Powerpoint document data to text.   Here is the sample Code   import java.io.*; import java.util.*; import org.apache.poi.hpsf.*; import org.apache.poi.poifs.eventfilesystem.*; import org.apache.poi.util.HexDump; import org.apache.poi.util.LittleEndian; /** *  Converts PPT Document Stream to Text *  @author Sudhakar Chavali ( href="mailto:sudhakar_koundinya@yahoo.com">sudhakar_koundinya@yahoo.com color=#0000ff>)    More>>





Hello all,


As I don't know how to share my codes here, I am placing this as question.
The following code converts Powerpoint document data to text.


 


Here is the sample Code


 


import java.io.*;
import java.util.*;
import
org.apache.poi.hpsf.*;
import
org.apache.poi.poifs.eventfilesystem.*;
import
org.apache.poi.util.HexDump;
import
org.apache.poi.util.LittleEndian;


/**
*  Converts PPT Document Stream to
Text
*  @author Sudhakar Chavali (
href="mailto:sudhakar_koundinya@yahoo.com">sudhakar_koundinya@yahoo.com

color=#0000ff>)
*/
public class PPT2Text
{
  static
FileOutputStream fos=null;
  public static void main(String[]
args)
   throws
IOException
  {
   final String filename =
args[0];
   POIFSReader r = new
POIFSReader();
   fos=new
FileOutputStream("output.txt");


   /* Register a listener for *all*
documents. */
   r.registerListener(new
MyPOIFSReaderListener());
   r.read(new
FileInputStream(filename));
  }



  static class MyPOIFSReaderListener
implements POIFSReaderListener
  {


   public void
processPOIFSReaderEvent(POIFSReaderEvent event)

   {
    PropertySet ps =
null;    
    try
    {     
     org.apache.poi.poifs.filesystem.DocumentInputStream
dis=null;
     if(!event.getName().equalsIgnoreCase("PowerPoint
Document"))
     {
                  
return;
     }
     dis=event.getStream();
     byte
btoWrite[]= new
byte[dis.available()];
     dis.read(btoWrite,0,dis.available());
     for(int
i=0;i
     {


      long
type=LittleEndian.getUShort(btoWrite,i+2);
      long
size=LittleEndian.getUInt(btoWrite,i+4);
      if
(type==4008)
      {
       fos.write(btoWrite,i+4+1,(int)size+3);
      }
     }
    }
    catch
(Exception
ex)
    {
     return;
    }
   }
  }
}









Sudhakar Chavali    <<Less
About | Sitemap | Contact