List of usage examples for org.apache.poi.hwpf.usermodel Range text
public String text()
From source file:com.xpn.xwiki.plugin.lucene.textextraction.MSWordTextExtractor.java
License:Apache License
public String getText(byte[] data) throws Exception { HWPFDocument wordDoc = new HWPFDocument(new ByteArrayInputStream(data)); Range range = wordDoc.getRange(); return range.text(); }
From source file:org.exoplatform.services.document.impl.MSWordDocumentReader.java
License:Open Source License
/** * Returns only a text from .doc file content. * //from w w w. jav a2 s. c o m * @param is an input stream with .doc file content. * @return The string only with text from file content. */ public String getContentAsText(final InputStream is) throws IOException, DocumentReadException { if (is == null) { throw new IllegalArgumentException("InputStream is null."); } String text = ""; try { if (is.available() == 0) { return ""; } HWPFDocument doc; try { doc = SecurityHelper.doPrivilegedIOExceptionAction(new PrivilegedExceptionAction<HWPFDocument>() { public HWPFDocument run() throws Exception { return new HWPFDocument(is); } }); } catch (IOException e) { throw new DocumentReadException("Can't open document.", e); } Range range = doc.getRange(); text = range.text(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { if (LOG.isTraceEnabled()) { LOG.trace("An exception occurred: " + e.getMessage()); } } } } return text.trim(); }