Example usage for org.apache.poi.xwpf.usermodel XWPFParagraph getParagraphText

List of usage examples for org.apache.poi.xwpf.usermodel XWPFParagraph getParagraphText

Introduction

In this page you can find the example usage for org.apache.poi.xwpf.usermodel XWPFParagraph getParagraphText.

Prototype

public String getParagraphText() 

Source Link

Document

Returns the text of the paragraph, but not of any objects in the paragraph

Usage

From source file:com.pdf.GetPdf.java

public static void docConvert(Document document, String url, String type)
        throws IOException, DocumentException {
    WordExtractor we;/* w w w . j  a  va2 s .c om*/

    if (type.equals("doc")) {
        HWPFDocument wordDoc = new HWPFDocument(new URL(url).openStream());
        we = new WordExtractor(wordDoc);
        String[] paragraphs = we.getParagraphText();
        for (int i = 0; i < paragraphs.length; i++) {
            paragraphs[i] = paragraphs[i].replaceAll("\\cM?\r?\n", "");
            document.add(new Paragraph(paragraphs[i]));
        }
    } else {
        XWPFDocument wordDoc = new XWPFDocument(new URL(url).openStream());
        List<IBodyElement> contents = wordDoc.getBodyElements();

        for (IBodyElement content : contents) {
            if (content.getElementType() == BodyElementType.PARAGRAPH) {
                List<XWPFParagraph> paras = content.getBody().getParagraphs();
                for (XWPFParagraph para : paras) {
                    document.add(new Paragraph(para.getParagraphText()));
                }

            } else if (content.getElementType() == BodyElementType.TABLE) {
                List<XWPFTable> tables = content.getBody().getTables();
                for (XWPFTable table : tables) {
                    List<XWPFTableRow> rows = table.getRows();
                    for (XWPFTableRow row : rows) {
                        List<XWPFTableCell> tablecells = row.getTableCells();
                    }
                }
            }

        }
    }

}

From source file:com.project3.utils.poi.DocumentPropertyChecker.java

public static Map<String, HashMap> checkRunPropertiesOfParagraphs(List<XWPFParagraph> pl, List<String> sl,
        Map<String, String> properties) {
    Map<String, HashMap> results = new HashMap<>(), tempMap = new HashMap<>();
    ArrayList tempList;// w w w .j  av  a  2  s.c  o m
    String removeString = "";

    // Initialize results, strings which were not found in the document are left as EXISTS : false
    for (String s : sl) {
        results.put(s, new HashMap<>());
        results.get(s).put("EXISTS", false);
    }

    for (XWPFParagraph p : pl) {
        for (String s : sl) {
            tempMap = null;
            //Will fail on typos, but pass on extra elements before or after string of interest
            //Need to change for typo toleration and exactness?
            if (p.getParagraphText().contains(s)) {
                tempList = new ArrayList();
                tempList.add(s);
                tempMap = checkPropertiesofParagraphRuns(p, tempList, properties);
                results.put(s, tempMap.get(s));
                removeString = s;
                break;
            }
        }
        //Remove string if it has been evaluated
        if (tempMap != null) {
            sl.remove(removeString);
        }
    }
    return results;
}

From source file:com.project3.utils.poi.DocumentPropertyChecker.java

public static Map<String, HashMap> checkPropertiesOfParagraphs(List<XWPFParagraph> pl, List<String> sl,
        Map<String, String> properties) {
    Map<String, HashMap> results = new HashMap<>(), tempMap = new HashMap<>();
    ArrayList tempList;//  www .  ja  v a2  s .c  o  m
    String removeString = "";

    // Initialize results, strings which were not found in the document are left as EXISTS : false
    for (String s : sl) {
        results.put(s, new HashMap<>());
        results.get(s).put("EXISTS", false);
    }

    for (XWPFParagraph p : pl) {
        for (String s : sl) {
            tempMap = null;
            //Will fail on typos, but pass on extra elements before or after string of interest
            //Need to change for typo toleration and exactness?
            if (p.getParagraphText().contains(s)) {
                tempMap = checkPropertiesofParagraph(p, s, properties);
                results.put(s, tempMap.get(s));
                removeString = s;
                break;
            }
        }
        //Remove string if it has been evaluated
        if (tempMap != null) {
            sl.remove(removeString);
        }
    }
    return results;
}

From source file:com.project3.utils.poiold.DocumentPropertyCheckerOld.java

public static Map<String, HashMap> checkRunPropertiesOfParagraphs(List<XWPFParagraph> pl, ArrayList<String> sl,
        Map<String, String> properties) {
    Map<String, HashMap> results = new HashMap<>(), tempMap = new HashMap<>();
    ArrayList<String> tempList;
    String removeString = "";

    // Initialize results, strings which were not found in the document are left as EXISTS : false
    for (String s : sl) {
        results.put(s, new HashMap<>());
        results.get(s).put("EXISTS", false);
    }/*from ww  w .  j a  va 2 s . co  m*/

    for (XWPFParagraph p : pl) {
        for (String s : sl) {
            tempMap = null;
            //Will fail on typos, but pass on extra elements before or after string of interest
            //Need to change for typo toleration and exactness?
            if (p.getParagraphText().contains(s)) {
                tempList = new ArrayList();
                tempList.add(s);
                tempMap = checkPropertiesofParagraphRuns(p, tempList, properties);
                results.put(s, tempMap.get(s));
                removeString = s;
                break;
            }
        }
        //Remove string if it has been evaluated
        if (tempMap != null) {
            sl.remove(removeString);
        }
    }
    return results;
}

From source file:com.project3.utils.poiold.DocumentPropertyEnumerator.java

public static void showAllParagraphProperties(List<XWPFParagraph> lp) {
    int i1 = 1;/*w  w  w . j a v a  2s  .  c o m*/
    for (XWPFParagraph p : lp) {
        //System.out.println(p.getStyleID() + " " + sl1.getStyle(p.getStyleID()).getCTStyle().xmlText());
        System.out.println("____________________________________");
        if (p.getParagraphText().trim().length() > 0) {
            System.out.println("\n#" + i1++ + " LINE: " + p.getParagraphText());
            System.out.println("ALIGNMENT: " + p.getAlignment().toString());

            System.out.println("BORDER BETWEEN: " + p.getBorderBetween().toString());
            System.out.println("BORDER BOTTOM: " + p.getBorderBottom().toString());
            System.out.println("BORDER LEFT: " + p.getBorderLeft().toString());
            System.out.println("BORDER RIGHT: " + p.getBorderRight().toString());
            System.out.println("BORDER TOP: " + p.getBorderTop().toString());
            System.out.println("BODY ELEMENT TYPE: " + p.getElementType().toString());
            System.out.println("FOOTNOTE: " + p.getFootnoteText());
            System.out.println("INDENTATION 1ST LINE: " + p.getIndentationFirstLine());
            System.out.println("INDENTATION HANGING: " + p.getIndentationHanging());
            System.out.println("INDENTATION LEFT: " + p.getIndentationLeft());
            System.out.println("INDENTATION RIGHT: " + p.getIndentationRight());
            System.out.println("NUMBERING FORMAT: " + p.getNumFmt());
            System.out.println("NUMERIC STYLE ILVL: " + p.getNumIlvl());
            System.out.println("STYLE: " + p.getBody().getXWPFDocument().getStyles().getStyle(p.getStyleID()));

            XWPFParagraphClone pc;
            pc = new XWPFParagraphClone(p.getCTP(), p.getBody());

            System.out.println("SPACING VALUE: " + pc.getCTSpacing(false).getLine().floatValue() / 240);
            System.out.println("SPACING AFTER: " + p.getSpacingAfter());
            System.out.println("SPACING AFTER LINES: " + p.getSpacingAfterLines());
            System.out.println("SPACING BEFORE: " + p.getSpacingBefore());
            System.out.println("SPACING BEFORE LINES: " + p.getSpacingBeforeLines());
            System.out.println("SPACING LINE RULE: " + p.getSpacingLineRule());
            System.out.println("VERTICAL ALIGNMENT: " + p.getVerticalAlignment());

        } // can also use .searchText to look for a string
        else {
            // Uncomment to display lines
            //System.out.println("\n#" + i1++ + " LINE: <SPACE>");
        }
    }
}

From source file:persistentie.PixelMapper.java

public List<String> leesDocFile(String bestandsNaam) {
    List<String> zin = new ArrayList<>();
    letterLijst = new ArrayList<>();
    File file = null;/*from  www .  j a v a2 s  .c  o  m*/
    XWPFWordExtractor extractor = null;
    try {
        XWPFDocument document = new XWPFDocument(Files.newInputStream(Paths.get(bestandsNaam)));
        List<XWPFParagraph> paragraphs = document.getParagraphs();
        for (XWPFParagraph par : paragraphs) {
            /**
             * Elke paragraph op spaties splitten en elk woord in de letterlijst plaatsen.
             */
            zin = Arrays.asList(par.getParagraphText().split(" "));
            for (String woord : zin) {
                letterLijst.add(woord);
                letterLijst.add(" ");
            }
            letterLijst.add("\n");
        }
    } catch (Exception exep) {
        exep.printStackTrace();
    }

    return letterLijst;
}