/** * Create a footer of the given type * * @param type {@link HeaderFooterType} enum * @return object of type {@link XWPFFooter} */ public XWPFFooter createFooter(HeaderFooterType type) { XWPFHeaderFooterPolicy hfPolicy = createHeaderFooterPolicy(); // TODO this needs to be migrated out into section code if (type == HeaderFooterType.FIRST) { CTSectPr ctSectPr = getSection(); if (!ctSectPr.isSetTitlePg()) { CTOnOff titlePg = ctSectPr.addNewTitlePg(); titlePg.setVal(STOnOff.ON); } // } else if (type == HeaderFooterType.EVEN) { // TODO Add support for Even/Odd headings and footers } return hfPolicy.createFooter(STHdrFtr.Enum.forInt(type.toInt())); }
/** * Create a header of the given type * * @param type {@link HeaderFooterType} enum * @return object of type {@link XWPFHeader} */ public XWPFHeader createHeader(HeaderFooterType type) { XWPFHeaderFooterPolicy hfPolicy = createHeaderFooterPolicy(); // TODO this needs to be migrated out into section code if (type == HeaderFooterType.FIRST) { CTSectPr ctSectPr = getSection(); if (!ctSectPr.isSetTitlePg()) { CTOnOff titlePg = ctSectPr.addNewTitlePg(); titlePg.setVal(STOnOff.ON); } // } else if (type == HeaderFooterType.EVEN) { // TODO Add support for Even/Odd headings and footers } return hfPolicy.createHeader(STHdrFtr.Enum.forInt(type.toInt())); }
/** * Create a header of the given type * * @param type {@link HeaderFooterType} enum * @return object of type {@link XWPFHeader} */ public XWPFHeader createHeader(HeaderFooterType type) { XWPFHeaderFooterPolicy hfPolicy = createHeaderFooterPolicy(); // TODO this needs to be migrated out into section code if (type == HeaderFooterType.FIRST) { CTSectPr ctSectPr = getSection(); if (!ctSectPr.isSetTitlePg()) { CTOnOff titlePg = ctSectPr.addNewTitlePg(); titlePg.setVal(STOnOff.ON); } // } else if (type == HeaderFooterType.EVEN) { // TODO Add support for Even/Odd headings and footers } return hfPolicy.createHeader(STHdrFtr.Enum.forInt(type.toInt())); }
/** * Create a footer of the given type * * @param type {@link HeaderFooterType} enum * @return object of type {@link XWPFFooter} */ public XWPFFooter createFooter(HeaderFooterType type) { XWPFHeaderFooterPolicy hfPolicy = createHeaderFooterPolicy(); // TODO this needs to be migrated out into section code if (type == HeaderFooterType.FIRST) { CTSectPr ctSectPr = getSection(); if (!ctSectPr.isSetTitlePg()) { CTOnOff titlePg = ctSectPr.addNewTitlePg(); titlePg.setVal(STOnOff.ON); } // } else if (type == HeaderFooterType.EVEN) { // TODO Add support for Even/Odd headings and footers } return hfPolicy.createFooter(STHdrFtr.Enum.forInt(type.toInt())); }
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) { } } }
pars[0] = p; XWPFHeaderFooterPolicy hfPolicy = doc.createHeaderFooterPolicy(); hfPolicy.createHeader(XWPFHeaderFooterPolicy.DEFAULT, pars);
XWPFHeaderFooterPolicy headerFooterPolicy = doc.createHeaderFooterPolicy(); XWPFHeader header = headerFooterPolicy.createHeader(XWPFHeaderFooterPolicy.DEFAULT);