Search in sources :

Example 6 with Paragraph

use of org.apache.poi.hwpf.usermodel.Paragraph in project tika by apache.

the class WordExtractor method handleHeaderFooter.

private void handleHeaderFooter(Range[] ranges, String type, HWPFDocument document, PicturesSource pictures, PicturesTable pictureTable, XHTMLContentHandler xhtml) throws SAXException, IOException, TikaException {
    if (countParagraphs(ranges) > 0) {
        xhtml.startElement("div", "class", type);
        ListManager listManager = new ListManager(document);
        for (Range r : ranges) {
            if (r != null) {
                for (int i = 0; i < r.numParagraphs(); i++) {
                    Paragraph p = r.getParagraph(i);
                    i += handleParagraph(p, 0, r, document, FieldsDocumentPart.HEADER, pictures, pictureTable, listManager, xhtml);
                }
            }
        }
        xhtml.endElement("div");
    }
}
Also used : Range(org.apache.poi.hwpf.usermodel.Range) Paragraph(org.apache.poi.hwpf.usermodel.Paragraph)

Example 7 with Paragraph

use of org.apache.poi.hwpf.usermodel.Paragraph in project poi by apache.

the class QuickTest method main.

public static void main(String[] args) throws IOException {
    HWPFDocument doc = new HWPFDocument(new FileInputStream(args[0]));
    Range r = doc.getRange();
    System.out.println("Example you supplied:");
    System.out.println("---------------------");
    for (int x = 0; x < r.numSections(); x++) {
        Section s = r.getSection(x);
        for (int y = 0; y < s.numParagraphs(); y++) {
            Paragraph p = s.getParagraph(y);
            for (int z = 0; z < p.numCharacterRuns(); z++) {
                // character run
                CharacterRun run = p.getCharacterRun(z);
                // character run text
                String text = run.text();
                // show us the text
                System.out.print(text);
            }
            // use a new line at the paragraph break
            System.out.println();
        }
    }
    doc.close();
}
Also used : CharacterRun(org.apache.poi.hwpf.usermodel.CharacterRun) Range(org.apache.poi.hwpf.usermodel.Range) Section(org.apache.poi.hwpf.usermodel.Section) FileInputStream(java.io.FileInputStream) Paragraph(org.apache.poi.hwpf.usermodel.Paragraph)

Example 8 with Paragraph

use of org.apache.poi.hwpf.usermodel.Paragraph in project poi by apache.

the class TestSprms method testInnerTable.

private void testInnerTable(HWPFDocument hwpfDocument) {
    Range range = hwpfDocument.getRange();
    for (int p = 0; p < range.numParagraphs(); p++) {
        Paragraph paragraph = range.getParagraph(p);
        char first = paragraph.text().toLowerCase(Locale.ROOT).charAt(0);
        if ('1' <= first && first < '4') {
            assertTrue(paragraph.isInTable());
            assertEquals(2, paragraph.getTableLevel());
        }
        if ('a' <= first && first < 'z') {
            assertTrue(paragraph.isInTable());
            assertEquals(1, paragraph.getTableLevel());
        }
    }
}
Also used : Range(org.apache.poi.hwpf.usermodel.Range) Paragraph(org.apache.poi.hwpf.usermodel.Paragraph)

Example 9 with Paragraph

use of org.apache.poi.hwpf.usermodel.Paragraph in project poi by apache.

the class HWPFLister method dumpParagraphsDom.

public void dumpParagraphsDom(boolean withText) {
    Range range = _doc.getOverallRange();
    for (int p = 0; p < range.numParagraphs(); p++) {
        Paragraph paragraph = range.getParagraph(p);
        System.out.println(p + ":\t" + paragraph);
        if (withText)
            System.out.println(paragraph.text());
    }
}
Also used : Range(org.apache.poi.hwpf.usermodel.Range) Paragraph(org.apache.poi.hwpf.usermodel.Paragraph)

Example 10 with Paragraph

use of org.apache.poi.hwpf.usermodel.Paragraph in project poi by apache.

the class WordExtractor method getParagraphText.

protected static String[] getParagraphText(Range r) {
    String[] ret;
    ret = new String[r.numParagraphs()];
    for (int i = 0; i < ret.length; i++) {
        Paragraph p = r.getParagraph(i);
        ret[i] = p.text();
        // Fix the line ending
        if (ret[i].endsWith("\r")) {
            ret[i] = ret[i] + "\n";
        }
    }
    return ret;
}
Also used : Paragraph(org.apache.poi.hwpf.usermodel.Paragraph)

Aggregations

Paragraph (org.apache.poi.hwpf.usermodel.Paragraph)12 Range (org.apache.poi.hwpf.usermodel.Range)8 HWPFDocument (org.apache.poi.hwpf.HWPFDocument)4 CharacterRun (org.apache.poi.hwpf.usermodel.CharacterRun)3 FileInputStream (java.io.FileInputStream)2 PicturesTable (org.apache.poi.hwpf.model.PicturesTable)2 Picture (org.apache.poi.hwpf.usermodel.Picture)2 Table (org.apache.poi.hwpf.usermodel.Table)2 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 OLEShape (org.apache.poi.hslf.model.OLEShape)1 HSLFObjectData (org.apache.poi.hslf.usermodel.HSLFObjectData)1 HSLFPictureData (org.apache.poi.hslf.usermodel.HSLFPictureData)1 HSLFPictureShape (org.apache.poi.hslf.usermodel.HSLFPictureShape)1 HSLFShape (org.apache.poi.hslf.usermodel.HSLFShape)1 HSLFSlide (org.apache.poi.hslf.usermodel.HSLFSlide)1 HSLFSlideShow (org.apache.poi.hslf.usermodel.HSLFSlideShow)1 HSLFSoundData (org.apache.poi.hslf.usermodel.HSLFSoundData)1