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();
}
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();
}
Aggregations