org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy Java Examples

The following examples show how to use org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WatermarkWordTests.java    From kbase-doc with Apache License 2.0 6 votes vote down vote up
@Test
public void testDocx2() throws IOException {
	String filepath = "E:\\ConvertTester\\docx\\NVR5X-I人脸比对配置-ekozhan.docx";
	XWPFDocument doc = new XWPFDocument(new FileInputStream(filepath));
	XWPFHeaderFooterPolicy policy = new XWPFHeaderFooterPolicy(doc);
	
	policy.createWatermark("ekozhan123");
	doc.write(new FileOutputStream("E:\\ConvertTester\\docx\\NVR5X-I人脸比对配置-ekozhan-11.docx"));
	doc.close();
}
 
Example #2
Source File: WordOOXMLDocument.java    From olat with Apache License 2.0 5 votes vote down vote up
private void extractFooters(final StringBuilder buffy, final XWPFHeaderFooterPolicy hfPolicy) {
    if (hfPolicy.getFirstPageFooter() != null) {
        buffy.append(hfPolicy.getFirstPageFooter().getText()).append(' ');
    }
    if (hfPolicy.getEvenPageFooter() != null) {
        buffy.append(hfPolicy.getEvenPageFooter().getText()).append(' ');
    }
    if (hfPolicy.getDefaultFooter() != null) {
        buffy.append(hfPolicy.getDefaultFooter().getText()).append(' ');
    }
}
 
Example #3
Source File: WordOOXMLDocument.java    From olat with Apache License 2.0 5 votes vote down vote up
private void extractHeaders(final StringBuilder buffy, final XWPFHeaderFooterPolicy hfPolicy) {
    if (hfPolicy.getFirstPageHeader() != null) {
        buffy.append(hfPolicy.getFirstPageHeader().getText()).append(' ');
    }
    if (hfPolicy.getEvenPageHeader() != null) {
        buffy.append(hfPolicy.getEvenPageHeader().getText()).append(' ');
    }
    if (hfPolicy.getDefaultHeader() != null) {
        buffy.append(hfPolicy.getDefaultHeader().getText()).append(' ');
    }
}
 
Example #4
Source File: WordOOXMLDocument.java    From olat with Apache License 2.0 5 votes vote down vote up
private void extractFooters(final StringBuilder buffy, final XWPFHeaderFooterPolicy hfPolicy) {
    if (hfPolicy.getFirstPageFooter() != null) {
        buffy.append(hfPolicy.getFirstPageFooter().getText()).append(' ');
    }
    if (hfPolicy.getEvenPageFooter() != null) {
        buffy.append(hfPolicy.getEvenPageFooter().getText()).append(' ');
    }
    if (hfPolicy.getDefaultFooter() != null) {
        buffy.append(hfPolicy.getDefaultFooter().getText()).append(' ');
    }
}
 
Example #5
Source File: WordOOXMLDocument.java    From olat with Apache License 2.0 5 votes vote down vote up
private void extractHeaders(final StringBuilder buffy, final XWPFHeaderFooterPolicy hfPolicy) {
    if (hfPolicy.getFirstPageHeader() != null) {
        buffy.append(hfPolicy.getFirstPageHeader().getText()).append(' ');
    }
    if (hfPolicy.getEvenPageHeader() != null) {
        buffy.append(hfPolicy.getEvenPageHeader().getText()).append(' ');
    }
    if (hfPolicy.getDefaultHeader() != null) {
        buffy.append(hfPolicy.getDefaultHeader().getText()).append(' ');
    }
}
 
Example #6
Source File: WatermarkServiceImpl.java    From kbase-doc with Apache License 2.0 4 votes vote down vote up
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) {
		
	}
}