public String getText() { StringBuilder text = new StringBuilder(64); XWPFHeaderFooterPolicy hfPolicy = document.getHeaderFooterPolicy(); // Start out with all headers extractHeaders(text, hfPolicy); // Process all body elements for (IBodyElement e : document.getBodyElements()) { appendBodyElementText(text, e); text.append('\n'); } // Finish up with all the footers extractFooters(text, hfPolicy); return text.toString(); }
protected void buildXHTML(XHTMLContentHandler xhtml) throws SAXException, XmlException, IOException { XWPFHeaderFooterPolicy hfPolicy = document.getHeaderFooterPolicy(); XWPFListManager listManager = new XWPFListManager(document.getNumbering());
public String getText() { StringBuilder text = new StringBuilder(64); XWPFHeaderFooterPolicy hfPolicy = document.getHeaderFooterPolicy(); // Start out with all headers extractHeaders(text, hfPolicy); // Process all body elements for (IBodyElement e : document.getBodyElements()) { appendBodyElementText(text, e); text.append('\n'); } // Finish up with all the footers extractFooters(text, hfPolicy); return text.toString(); }
String text = "Test"; File docxFile = new File("C:/testeXWPF.docx"); FileInputStream finStream = new FileInputStream(docxFile.getAbsolutePath()); XWPFDocument doc = new XWPFDocument(finStream); XWPFHeaderFooterPolicy policy = doc.getHeaderFooterPolicy(); if (policy == null) { policy = new XWPFHeaderFooterPolicy(doc); } CTP ctP1 = CTP.Factory.newInstance(); CTR ctR1 = ctP1.addNewR(); CTText t = ctR1.addNewT(); t.setStringValue(text); XWPFParagraph codePara = new XWPFParagraph(ctP1); XWPFParagraph[] newparagraphs = new XWPFParagraph[1]; newparagraphs[0] = codePara; policy.createFooter(policy.DEFAULT, newparagraphs); FileOutputStream fileOut = new FileOutputStream(docxFile); doc.write(fileOut); fileOut.close();
public void test1() throws IOException{ XWPFDocument sampleDoc = new XWPFDocument(); XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy(); //in an empty document always will be null if(policy==null){ CTSectPr sectPr = sampleDoc.getDocument().getBody().addNewSectPr(); policy = new XWPFHeaderFooterPolicy( sampleDoc, sectPr ); } if (policy.getDefaultHeader() == null && policy.getFirstPageHeader() == null && policy.getDefaultFooter() == null) { XWPFHeader headerD = policy.createHeader(policy.DEFAULT); headerD.getParagraphs().get(0).createRun().setText("Hello Header World!"); } FileOutputStream out = new FileOutputStream(System.currentTimeMillis()+"_test1_header.docx"); sampleDoc.write(out); out.close(); sampleDoc.close(); }
/** * @see org.apache.poi.xwpf.extractor.XWPFWordExtractor#getText() */ @Override protected void buildXHTML(XHTMLContentHandler xhtml) throws SAXException, XmlException, IOException { XWPFHeaderFooterPolicy hfPolicy = document.getHeaderFooterPolicy(); XWPFListManager listManager = new XWPFListManager(document.getNumbering()); // headers if (hfPolicy != null) { extractHeaders(xhtml, hfPolicy, listManager); } // process text in the order that it occurs in extractIBodyText(document, listManager, xhtml); // then all document tables if (hfPolicy != null) { extractFooters(xhtml, hfPolicy, listManager); } }
public String getText() { StringBuffer text = new StringBuffer(); XWPFHeaderFooterPolicy hfPolicy = document.getHeaderFooterPolicy();
private void addWaterMark(Object obj, String watermark, String color) { if (obj instanceof XWPFDocument) { XWPFDocument doc = (XWPFDocument) obj; // create header-footer XWPFHeaderFooterPolicy headerFooterPolicy = doc.getHeaderFooterPolicy(); if (headerFooterPolicy == null) headerFooterPolicy = doc.createHeaderFooterPolicy(); // create default Watermark - fill color black and not rotated headerFooterPolicy.createWatermark(watermark); // get the default header // Note: createWatermark also sets FIRST and EVEN headers // but this code does not updating those other headers XWPFHeader header = headerFooterPolicy.getHeader(XWPFHeaderFooterPolicy.DEFAULT); XWPFParagraph paragraph = header.getParagraphArray(0); // get com.microsoft.schemas.vml.CTShape where fill color and rotation is set XmlObject[] xmlobjects = paragraph.getCTP().getRArray(0).getPictArray(0).selectChildren(new QName("urn:schemas-microsoft-com:vml", "shape")); if (xmlobjects.length > 0) { com.microsoft.schemas.vml.CTShape ctshape = (com.microsoft.schemas.vml.CTShape)xmlobjects[0]; // set fill color ctshape.setFillcolor(color); // set rotation ctshape.setStyle(ctshape.getStyle() + ";rotation:315"); } } else if (obj instanceof HWPFDocument) { } } }
protected void buildXHTML(XHTMLContentHandler xhtml) throws SAXException, XmlException, IOException { XWPFHeaderFooterPolicy hfPolicy = document.getHeaderFooterPolicy(); XWPFListManager listManager = new XWPFListManager(document.getNumbering());