Sorry, wrong code. It's following code for the POI.
String txt = "";
POITextExtractor txtExtractor = null;
try{
txtExtractor = ExtractorFactory.createExtractor(in);
txt = txtExtractor.getText();
txt = txt.trim();
txtExtractor = null;
//poiFactory = null;
}catch(Exception e){
log.error(e.getMessage(),e);
}
txt = txt.trim();
return txt;
-----Original Message-----
From: Jeffrey Zhao [mailto:[email protected]]
Sent: February 8, 2012 8:56 AM
To: [email protected]
Subject: POI freezing?
I'm using POI to get text contents and having intermittent freezing. The java
thread calling this part hangs sometimes.
Have you experience similar problems? I'm using following code.
PDFParser parser;
String parsedText = null;
PDFTextStripper pdfStripper = null;
PDDocument pdDoc = null;
COSDocument cosDoc = null;
try {
parser = new PDFParser(in);
parser.parse();
cosDoc = parser.getDocument();
pdfStripper = new PDFTextStripper();
pdDoc = new PDDocument(cosDoc);
if(!pdDoc.isEncrypted()){
pdfStripper.setStartPage(1);
pdfStripper.setEndPage(Integer.MAX_VALUE);
parsedText = pdfStripper.getText(pdDoc);
}else{
log.error("PDF Failed (" + fname+ ") Encrypted");
}
} catch (Exception e) {
log.error("PDF Failed (" + fname + ") Error: " +
e.getMessage());
} finally {
try {
if (cosDoc != null){
cosDoc.close();
}
if (pdDoc != null){
pdDoc.close();
}
} catch (Exception e) {
log.error("PDF Close (" + fname + ") Error: " +
e.getMessage());
}
}