Search in sources :

Example 1 with QCTextBit

use of org.apache.poi.hpbf.model.qcbits.QCTextBit in project poi by apache.

the class TestQuillContents method testText.

@Test
public void testText() throws IOException {
    HPBFDocument doc = new HPBFDocument(_samples.openResourceAsStream("Sample.pub"));
    QuillContents qc = doc.getQuillContents();
    assertEquals(20, qc.getBits().length);
    QCTextBit text = (QCTextBit) qc.getBits()[0];
    String t = text.getText();
    assertStartsWith(t, "This is some text on the first page");
    assertEndsWith(t, "Within doc to page 1\r");
    doc.close();
}
Also used : QCTextBit(org.apache.poi.hpbf.model.qcbits.QCTextBit) HPBFDocument(org.apache.poi.hpbf.HPBFDocument) Test(org.junit.Test)

Example 2 with QCTextBit

use of org.apache.poi.hpbf.model.qcbits.QCTextBit in project poi by apache.

the class PublisherTextExtractor method getText.

public String getText() {
    StringBuffer text = new StringBuffer();
    // Get the text from the Quill Contents
    QCBit[] bits = doc.getQuillContents().getBits();
    for (int i = 0; i < bits.length; i++) {
        if (bits[i] != null && bits[i] instanceof QCTextBit) {
            QCTextBit t = (QCTextBit) bits[i];
            text.append(t.getText().replace('\r', '\n'));
        }
    }
    //  how to tie that together.
    if (hyperlinksByDefault) {
        for (int i = 0; i < bits.length; i++) {
            if (bits[i] != null && bits[i] instanceof Type12) {
                Type12 hyperlinks = (Type12) bits[i];
                for (int j = 0; j < hyperlinks.getNumberOfHyperlinks(); j++) {
                    text.append("<");
                    text.append(hyperlinks.getHyperlink(j));
                    text.append(">\n");
                }
            }
        }
    }
    return text.toString();
}
Also used : QCTextBit(org.apache.poi.hpbf.model.qcbits.QCTextBit) QCBit(org.apache.poi.hpbf.model.qcbits.QCBit) Type12(org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type12)

Aggregations

QCTextBit (org.apache.poi.hpbf.model.qcbits.QCTextBit)2 HPBFDocument (org.apache.poi.hpbf.HPBFDocument)1 QCBit (org.apache.poi.hpbf.model.qcbits.QCBit)1 Type12 (org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type12)1 Test (org.junit.Test)1