Search in sources :

Example 1 with WordToTextConverter

use of org.apache.poi.hwpf.converter.WordToTextConverter in project poi by apache.

the class WordExtractor method getText.

/**
     * Grab the text, based on the WordToTextConverter. Shouldn't include any
     * crud, but slower than getTextFromPieces().
     */
public String getText() {
    try {
        WordToTextConverter wordToTextConverter = new WordToTextConverter();
        HeaderStories hs = new HeaderStories(doc);
        if (hs.getFirstHeaderSubrange() != null)
            wordToTextConverter.processDocumentPart(doc, hs.getFirstHeaderSubrange());
        if (hs.getEvenHeaderSubrange() != null)
            wordToTextConverter.processDocumentPart(doc, hs.getEvenHeaderSubrange());
        if (hs.getOddHeaderSubrange() != null)
            wordToTextConverter.processDocumentPart(doc, hs.getOddHeaderSubrange());
        wordToTextConverter.processDocument(doc);
        wordToTextConverter.processDocumentPart(doc, doc.getMainTextboxRange());
        if (hs.getFirstFooterSubrange() != null)
            wordToTextConverter.processDocumentPart(doc, hs.getFirstFooterSubrange());
        if (hs.getEvenFooterSubrange() != null)
            wordToTextConverter.processDocumentPart(doc, hs.getEvenFooterSubrange());
        if (hs.getOddFooterSubrange() != null)
            wordToTextConverter.processDocumentPart(doc, hs.getOddFooterSubrange());
        return wordToTextConverter.getText();
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception exc) {
        throw new RuntimeException(exc);
    }
}
Also used : HeaderStories(org.apache.poi.hwpf.usermodel.HeaderStories) WordToTextConverter(org.apache.poi.hwpf.converter.WordToTextConverter) IOException(java.io.IOException)

Example 2 with WordToTextConverter

use of org.apache.poi.hwpf.converter.WordToTextConverter in project poi by apache.

the class Word6Extractor method getText.

public String getText() {
    try {
        WordToTextConverter wordToTextConverter = new WordToTextConverter();
        wordToTextConverter.processDocument(doc);
        return wordToTextConverter.getText();
    } catch (Exception exc) {
        // fall-back
        StringBuffer text = new StringBuffer();
        for (String t : getParagraphText()) {
            text.append(t);
        }
        return text.toString();
    }
}
Also used : WordToTextConverter(org.apache.poi.hwpf.converter.WordToTextConverter) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 WordToTextConverter (org.apache.poi.hwpf.converter.WordToTextConverter)2 HeaderStories (org.apache.poi.hwpf.usermodel.HeaderStories)1