You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by "Natarajan.T" <na...@crimsonlogic.co.in> on 2004/07/27 15:38:18 UTC
Title info. form PPT Doc.
FYI,
See the below attached code.(Convert PPT to text).
The problem is I want to display the Title using the this below
functions
summaryinformation =
(SummaryInformation)PropertySetFactory.create(event.getStream());
String a = summaryinformation.getTitle();
System.out.println("Title :"+a);
The above functions are not working, so how I handle this one? Advice
me.
Pls look my code.
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.hpsf.PropertySet;
import org.apache.poi.hpsf.PropertySetFactory;
import org.apache.poi.poifs.eventfilesystem.POIFSReader;
import org.apache.poi.poifs.eventfilesystem.POIFSReaderEvent;
import org.apache.poi.poifs.eventfilesystem.POIFSReaderListener;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hpsf.*;
/**
* Class description
*
*
*/
public class PPTConverterImpl extends JavaDocumentConverter {
static final String lineSeparator =
System.getProperty("line.separator");
/**
* Extract the text from a number of presentations.
*/
public boolean extractText(InputStream reader, BufferedWriter
writer) throws IOException{
System.out.println("Title :");
POIFSReader r = new POIFSReader();
/* Register a listener for *all* documents. */
MyPOIFSReaderListener listener = new
MyPOIFSReaderListener(writer);
r.registerListener(listener);
r.read(reader);
//if no exception was trown, consider that the conversion
was successful
return true;
}
class MyPOIFSReaderListener implements POIFSReaderListener{
private BufferedWriter writer = null;
public MyPOIFSReaderListener(BufferedWriter writer){
this.writer = writer;
}
public void processPOIFSReaderEvent(POIFSReaderEvent event) {
org.apache.poi.hpsf.PropertySet ps = null;
SummaryInformation summaryinformation = null;
try{
org.apache.poi.poifs.filesystem.DocumentInputStream
dis=null;
if(!event.getName().equalsIgnoreCase("PowerPoint
Document"))
return;
dis=event.getStream();
summaryinformation =
(SummaryInformation)PropertySetFactory.create(event.getStream());
String a = summaryinformation.getTitle();
System.out.println("Title :"+a);
byte btoWrite[]= new byte[12];
dis.read(btoWrite);
btoWrite = new byte[dis.available()];
System.out.println(btoWrite);
dis.read(btoWrite, 0, dis.available());
StringBuffer buff = new StringBuffer("");
//String x = "";
for(int i=0; i<btoWrite.length-20; i++){
long type=LittleEndian.getUShort(btoWrite,i+2);
long size=LittleEndian.getUInt(btoWrite,i+4);
if (type==4008){
int offset = i+4+1;
int length = (int)size+3;
int end = offset + length;
byte[] textBytes = new byte[length];
for (int j = offset; j < end; j++) {
byte b = btoWrite[j];
buff = buff.append((char)b);
writer.write((char) b);
}
if(i < (end -1))
i = end -1;
}
}
}catch (Exception e){
/*String msg = "Cannot index ppt file: \n";
if(getLogger().isErrorEnabled())
getLogger().error(msg + e);*/
}
}
}
}