org.docx4j.wml.ObjectFactory Java Examples

The following examples show how to use org.docx4j.wml.ObjectFactory. 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: Docx4J_例子2.java    From docx4j-template with Apache License 2.0 10 votes vote down vote up
public Ftr getFtr(WordprocessingMLPackage wordprocessingMLPackage,
		ObjectFactory factory, Part sourcePart, boolean isUnderLine,
		String underLineSz) throws Exception {
	Ftr ftr = factory.createFtr();
	File file = new File("f:/saveFile/tmp/xxt.jpg");
	java.io.InputStream is = new java.io.FileInputStream(file);
	ftr.getContent().add(
			newImage(wordprocessingMLPackage, factory, sourcePart,
					BufferUtil.getBytesFromInputStream(is), "filename",
					"这是页脚", 1, 2, isUnderLine, underLineSz,
					JcEnumeration.CENTER));
	if (isUnderLine) {
		ftr.getContent().add(
				createHeaderBlankP(wordprocessingMLPackage, factory,
						underLineSz, JcEnumeration.CENTER));
	}
	return ftr;
}
 
Example #2
Source File: Docx4j_创建表格_S5_Test.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
public void setPageMargins(WordprocessingMLPackage wordMLPackage,  
        ObjectFactory factory) {  
    try {  
        Body body = wordMLPackage.getMainDocumentPart().getContents()  
                .getBody();  
        PageDimensions page = new PageDimensions();  
        PgMar pgMar = page.getPgMar();  
        pgMar.setBottom(BigInteger.valueOf(pixelsToDxa(50)));  
        pgMar.setTop(BigInteger.valueOf(pixelsToDxa(50)));  
        pgMar.setLeft(BigInteger.valueOf(pixelsToDxa(50)));  
        pgMar.setRight(BigInteger.valueOf(pixelsToDxa(50)));  
        SectPr sectPr = factory.createSectPr();  
        body.setSectPr(sectPr);  
        sectPr.setPgMar(pgMar);  
    } catch (Exception e) {  
        e.printStackTrace();  
    }  
}
 
Example #3
Source File: Docx4j_工具类_S3_Test.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
/**
 * @Description:设置页边距
 */
public void setDocMarginSpace(WordprocessingMLPackage wordPackage,
        ObjectFactory factory, String top, String left, String bottom,
        String right) {
    SectPr sectPr = getDocSectPr(wordPackage);
    PgMar pg = sectPr.getPgMar();
    if (pg == null) {
        pg = factory.createSectPrPgMar();
        sectPr.setPgMar(pg);
    }
    if (StringUtils.isNotBlank(top)) {
        pg.setTop(new BigInteger(top));
    }
    if (StringUtils.isNotBlank(bottom)) {
        pg.setBottom(new BigInteger(bottom));
    }
    if (StringUtils.isNotBlank(left)) {
        pg.setLeft(new BigInteger(left));
    }
    if (StringUtils.isNotBlank(right)) {
        pg.setRight(new BigInteger(right));
    }
}
 
Example #4
Source File: Docx4j_工具类_S3_Test.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
/**
 * @Description: 添加图片到段落
 */
public void addImageToPara(WordprocessingMLPackage wordMLPackage,
        ObjectFactory factory, P paragraph, String filePath,
        String content, RPr rpr, String altText, int id1, int id2)
        throws Exception {
    R run = factory.createR();
    if (content != null) {
        Text text = factory.createText();
        text.setValue(content);
        text.setSpace("preserve");
        run.setRPr(rpr);
        run.getContent().add(text);
    }

    InputStream is = new FileInputStream(filePath);
    byte[] bytes = IOUtils.toByteArray(is);
    BinaryPartAbstractImage imagePart = BinaryPartAbstractImage
            .createImagePart(wordMLPackage, bytes);
    Inline inline = imagePart.createImageInline(filePath, altText, id1,
            id2, false);
    Drawing drawing = factory.createDrawing();
    drawing.getAnchorOrInline().add(inline);
    run.getContent().add(drawing);
    paragraph.getContent().add(run);
}
 
Example #5
Source File: WmlElementUtils.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
/**
 * @Description: 设置页面大小及纸张方向 landscape横向
 */
public static void setDocumentSize(WordprocessingMLPackage wordPackage, ObjectFactory factory, String width, String height,
        STPageOrientation stValue) {
    SectPr sectPr = getDocSectPr(wordPackage);
    PgSz pgSz = sectPr.getPgSz();
    if (pgSz == null) {
        pgSz = factory.createSectPrPgSz();
        sectPr.setPgSz(pgSz);
    }
    if (StringUtils.isNotBlank(width)) {
        pgSz.setW(new BigInteger(width));
    }
    if (StringUtils.isNotBlank(height)) {
        pgSz.setH(new BigInteger(height));
    }
    if (stValue != null) {
        pgSz.setOrient(stValue);
    }
}
 
Example #6
Source File: Docx4j_工具类_S3_Test.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
/**
 * @Description: 设置页面大小及纸张方向 landscape横向
 */
public void setDocumentSize(WordprocessingMLPackage wordPackage,
        ObjectFactory factory, String width, String height,
        STPageOrientation stValue) {
    SectPr sectPr = getDocSectPr(wordPackage);
    PgSz pgSz = sectPr.getPgSz();
    if (pgSz == null) {
        pgSz = factory.createSectPrPgSz();
        sectPr.setPgSz(pgSz);
    }
    if (StringUtils.isNotBlank(width)) {
        pgSz.setW(new BigInteger(width));
    }
    if (StringUtils.isNotBlank(height)) {
        pgSz.setH(new BigInteger(height));
    }
    if (stValue != null) {
        pgSz.setOrient(stValue);
    }
}
 
Example #7
Source File: WmlElementUtils.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
/**
 * @Description: 设置页面边框
 */
public static void setDocumentBorders(WordprocessingMLPackage wordPackage, ObjectFactory factory, CTBorder top,
        CTBorder right, CTBorder bottom, CTBorder left) {
    SectPr sectPr = getDocSectPr(wordPackage);
    PgBorders pgBorders = sectPr.getPgBorders();
    if (pgBorders == null) {
        pgBorders = factory.createSectPrPgBorders();
        sectPr.setPgBorders(pgBorders);
    }
    if (top != null) {
        pgBorders.setTop(top);
    }
    if (right != null) {
        pgBorders.setRight(right);
    }
    if (bottom != null) {
        pgBorders.setBottom(bottom);
    }
    if (left != null) {
        pgBorders.setLeft(left);
    }
}
 
Example #8
Source File: Docx4j_工具类_S3_Test.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
/**
 * @Description: 设置页面边框
 */
public void setDocumentBorders(WordprocessingMLPackage wordPackage,
        ObjectFactory factory, CTBorder top, CTBorder right,
        CTBorder bottom, CTBorder left) {
    SectPr sectPr = getDocSectPr(wordPackage);
    PgBorders pgBorders = sectPr.getPgBorders();
    if (pgBorders == null) {
        pgBorders = factory.createSectPrPgBorders();
        sectPr.setPgBorders(pgBorders);
    }
    if (top != null) {
        pgBorders.setTop(top);
    }
    if (right != null) {
        pgBorders.setRight(right);
    }
    if (bottom != null) {
        pgBorders.setBottom(bottom);
    }
    if (left != null) {
        pgBorders.setLeft(left);
    }
}
 
Example #9
Source File: BackgroundImage.java    From kbase-doc with Apache License 2.0 6 votes vote down vote up
private static CTBackground createBackground(String rId) {

		org.docx4j.wml.ObjectFactory wmlObjectFactory = new org.docx4j.wml.ObjectFactory();

		CTBackground background = wmlObjectFactory.createCTBackground();
		background.setColor("FF0000");
		org.docx4j.vml.ObjectFactory vmlObjectFactory = new org.docx4j.vml.ObjectFactory();
		// Create object for background (wrapped in JAXBElement)
		org.docx4j.vml.CTBackground background2 = vmlObjectFactory
				.createCTBackground();
		JAXBElement<org.docx4j.vml.CTBackground> backgroundWrapped = vmlObjectFactory
				.createBackground(background2);
		background.getAnyAndAny().add(backgroundWrapped);
		background2.setTargetscreensize("1024,768");
		background2.setVmlId("_x0000_s1025");
		background2.setBwmode(org.docx4j.vml.officedrawing.STBWMode.LIGHT_GRAYSCALE);
		// Create object for fill
		CTFill fill = vmlObjectFactory.createCTFill();
		background2.setFill(fill);
		fill.setTitle("Alien 1");
		fill.setId(rId);
		fill.setType(org.docx4j.vml.STFillType.FRAME);
		fill.setRecolor(org.docx4j.vml.STTrueFalse.T);

		return background;
	}
 
Example #10
Source File: Docx4J_简单例子.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
public void createHeaderReference(
		WordprocessingMLPackage wordprocessingMLPackage,
		MainDocumentPart t, ObjectFactory factory, Relationship relationship)
		throws InvalidFormatException {
	List<SectionWrapper> sections = wordprocessingMLPackage
			.getDocumentModel().getSections();
	SectPr sectPr = sections.get(sections.size() - 1).getSectPr();
	// There is always a section wrapper, but it might not contain a sectPr
	if (sectPr == null) {
		sectPr = factory.createSectPr();
		t.addObject(sectPr);
		sections.get(sections.size() - 1).setSectPr(sectPr);
	}
	HeaderReference headerReference = factory.createHeaderReference();
	headerReference.setId(relationship.getId());
	headerReference.setType(HdrFtrRef.DEFAULT);
	sectPr.getEGHdrFtrReferences().add(headerReference);
}
 
Example #11
Source File: Docx4J_简单例子.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
public Hdr getTextHdr(WordprocessingMLPackage wordprocessingMLPackage,
		ObjectFactory factory, Part sourcePart, String content,
		JcEnumeration jcEnumeration) throws Exception {
	Hdr hdr = factory.createHdr();
	P headP = factory.createP();
	Text text = factory.createText();
	text.setValue(content);
	R run = factory.createR();
	run.getContent().add(text);
	headP.getContent().add(run);

	PPr pPr = headP.getPPr();
	if (pPr == null) {
		pPr = factory.createPPr();
	}
	Jc jc = pPr.getJc();
	if (jc == null) {
		jc = new Jc();
	}
	jc.setVal(jcEnumeration);
	pPr.setJc(jc);
	headP.setPPr(pPr);
	hdr.getContent().add(headP);
	return hdr;
}
 
Example #12
Source File: Docx4J_简单例子.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
public Ftr getTextFtr(WordprocessingMLPackage wordprocessingMLPackage,
		ObjectFactory factory, Part sourcePart, String content,
		JcEnumeration jcEnumeration) throws Exception {
	Ftr ftr = factory.createFtr();
	P footerP = factory.createP();
	Text text = factory.createText();
	text.setValue(content);
	R run = factory.createR();
	run.getContent().add(text);
	footerP.getContent().add(run);

	PPr pPr = footerP.getPPr();
	if (pPr == null) {
		pPr = factory.createPPr();
	}
	Jc jc = pPr.getJc();
	if (jc == null) {
		jc = new Jc();
	}
	jc.setVal(jcEnumeration);
	pPr.setJc(jc);
	footerP.setPPr(pPr);
	ftr.getContent().add(footerP);
	return ftr;
}
 
Example #13
Source File: Docx4J_简单例子.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
	Docx4J_简单例子 t = new Docx4J_简单例子();
	WordprocessingMLPackage wordMLPackage = t
			.createWordprocessingMLPackage();
	MainDocumentPart mp = wordMLPackage.getMainDocumentPart();
	ObjectFactory factory = Context.getWmlObjectFactory();
	//页眉
	Relationship relationship =t.createHeaderPart(wordMLPackage, mp, factory);
	t.createHeaderReference(wordMLPackage, mp, factory, relationship);
	
	t.addParagraphTest(wordMLPackage, mp, factory);
	t.addPageBreak(wordMLPackage, factory);
	//页脚
	t.createNormalTableTest(wordMLPackage, mp, factory);
	relationship =t.createFooterPageNumPart(wordMLPackage, mp, factory);
	t.createFooterReference(wordMLPackage, mp, factory, relationship);
	
	t.saveWordPackage(wordMLPackage, new File(
			"f:/saveFile/temp/s_simple.docx"));
}
 
Example #14
Source File: Docx4j_创建批注_S3_Test.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
public void createCommentRound(ObjectFactory factory, P p, String pContent,  
        String commentContent, RPr fontRPr, RPr commentRPr,  
        BigInteger commentId, Comments comments) throws Exception {  
    CommentRangeStart startComment = factory.createCommentRangeStart();  
    startComment.setId(commentId);  
    p.getContent().add(startComment);  
    R run = factory.createR();  
    Text txt = factory.createText();  
    txt.setValue(pContent);  
    run.getContent().add(txt);  
    run.setRPr(fontRPr);  
    p.getContent().add(run);  
    CommentRangeEnd endComment = factory.createCommentRangeEnd();  
    endComment.setId(commentId);  
    p.getContent().add(endComment);  
    Comment commentOne = createComment(factory, commentId, "系统管理员",  
            new Date(), commentContent, commentRPr);  
    comments.getComment().add(commentOne);  
    p.getContent().add(createRunCommentReference(factory, commentId));  
}
 
Example #15
Source File: Docx4j_创建批注_S3_Test.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
public Comments.Comment createComment(ObjectFactory factory,  
        BigInteger commentId, String author, Date date,  
        String commentContent, RPr commentRPr) throws Exception {  
    Comments.Comment comment = factory.createCommentsComment();  
    comment.setId(commentId);  
    if (author != null) {  
        comment.setAuthor(author);  
    }  
    if (date != null) {  
        comment.setDate(toXMLCalendar(date));  
    }  
    P commentP = factory.createP();  
    comment.getEGBlockLevelElts().add(commentP);  
    R commentR = factory.createR();  
    commentP.getContent().add(commentR);  
    Text commentText = factory.createText();  
    commentR.getContent().add(commentText);  
    commentR.setRPr(commentRPr);  
    commentText.setValue(commentContent);  
    return comment;  
}
 
Example #16
Source File: Docx4j_创建批注_S3_Test.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
public void setParagraphAlign(ObjectFactory factory, P p,  
        JcEnumeration jcEnumeration, TextAlignment textAlign) {  
    PPr pPr = p.getPPr();  
    if (pPr == null) {  
        pPr = factory.createPPr();  
    }  
    if (jcEnumeration != null) {  
        Jc jc = pPr.getJc();  
        if (jc == null) {  
            jc = new Jc();  
        }  
        jc.setVal(jcEnumeration);  
        pPr.setJc(jc);  
    }  
    if (textAlign != null) {  
        pPr.setTextAlignment(textAlign);  
    }  
    p.setPPr(pPr);  
}
 
Example #17
Source File: Docx4j_创建表格_S5_Test.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
public P newImage(WordprocessingMLPackage wordMLPackage,  
        ObjectFactory factory, byte[] bytes, String filenameHint,  
        String altText, int id1, int id2, long cx) throws Exception {  
    BinaryPartAbstractImage imagePart = BinaryPartAbstractImage  
            .createImagePart(wordMLPackage, bytes);  
    Inline inline = imagePart.createImageInline(filenameHint, altText, id1,  
            id2, cx, false);  
    // Now add the inline in w:p/w:r/w:drawing  
    P p = factory.createP();  
    R run = factory.createR();  
    p.getContent().add(run);  
    Drawing drawing = factory.createDrawing();  
    run.getContent().add(drawing);  
    drawing.getAnchorOrInline().add(inline);  
    return p;  
}
 
Example #18
Source File: Docx4J_简单例子2.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
public void setParagraphSpacing(ObjectFactory factory, P p,  
        JcEnumeration jcEnumeration,String before,String after) {  
    PPr pPr = p.getPPr();  
    if (pPr == null) {  
        pPr = factory.createPPr();  
    }  
    Jc jc = pPr.getJc();  
    if (jc == null) {  
        jc = new Jc();  
    }  
    jc.setVal(jcEnumeration);  
    pPr.setJc(jc);  
      
    Spacing spacing=new Spacing();  
    spacing.setBefore(new BigInteger(before));  
    spacing.setAfter(new BigInteger(after));  
    spacing.setLineRule(STLineSpacingRule.AUTO);  
    pPr.setSpacing(spacing);  
    p.setPPr(pPr);  
}
 
Example #19
Source File: Docx4J_简单例子2.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
public Ftr createFooterWithPageNr(ObjectFactory factory) {  
    Ftr ftr = factory.createFtr();  
    P paragraph = factory.createP();  
    RPr fontRPr = getRPr(factory, "宋体", "000000", "20", STHint.EAST_ASIA,  
            false, false, false, false);  
    R run = factory.createR();  
    run.setRPr(fontRPr);  
    paragraph.getContent().add(run);  
  
    addPageTextField(factory, paragraph, "第");  
    addFieldBegin(factory, paragraph);  
    addPageNumberField(factory, paragraph);  
    addFieldEnd(factory, paragraph);  
    addPageTextField(factory, paragraph, "页");  
  
    addPageTextField(factory, paragraph, " 总共");  
    addFieldBegin(factory, paragraph);  
    addTotalPageNumberField(factory, paragraph);  
    addFieldEnd(factory, paragraph);  
    addPageTextField(factory, paragraph, "页");  
    setParagraphAlign(factory, paragraph, JcEnumeration.CENTER);  
    ftr.getContent().add(paragraph);  
    return ftr;  
}
 
Example #20
Source File: Docx4J_例子2.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
public void createHeaderReference(
		WordprocessingMLPackage wordprocessingMLPackage,
		MainDocumentPart t, ObjectFactory factory, Relationship relationship)
		throws InvalidFormatException {
	List<SectionWrapper> sections = wordprocessingMLPackage
			.getDocumentModel().getSections();
	SectPr sectPr = sections.get(sections.size() - 1).getSectPr();
	// There is always a section wrapper, but it might not contain a sectPr
	if (sectPr == null) {
		sectPr = factory.createSectPr();
		t.addObject(sectPr);
		sections.get(sections.size() - 1).setSectPr(sectPr);
	}
	HeaderReference headerReference = factory.createHeaderReference();
	headerReference.setId(relationship.getId());
	headerReference.setType(HdrFtrRef.DEFAULT);
	sectPr.getEGHdrFtrReferences().add(headerReference);
}
 
Example #21
Source File: Docx4J_简单例子2.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
public void createFooterReference(  
        WordprocessingMLPackage wordprocessingMLPackage,  
        MainDocumentPart t, ObjectFactory factory, Relationship relationship)  
        throws InvalidFormatException {  
    List<SectionWrapper> sections = wordprocessingMLPackage  
            .getDocumentModel().getSections();  
    SectPr sectPr = sections.get(sections.size() - 1).getSectPr();  
    // There is always a section wrapper, but it might not contain a sectPr  
    if (sectPr == null) {  
        sectPr = factory.createSectPr();  
        t.addObject(sectPr);  
        sections.get(sections.size() - 1).setSectPr(sectPr);  
    }  
    FooterReference footerReference = factory.createFooterReference();  
    footerReference.setId(relationship.getId());  
    footerReference.setType(HdrFtrRef.DEFAULT);  
    sectPr.getEGHdrFtrReferences().add(footerReference);  
}
 
Example #22
Source File: Docx4J_简单例子.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public void addPageNumberField(ObjectFactory factory, P paragraph) {
	R run = factory.createR();
	Text txt = new Text();
	txt.setSpace("preserve");
	txt.setValue("PAGE  \\* MERGEFORMAT ");
	run.getContent().add(factory.createRInstrText(txt));
	paragraph.getContent().add(run);
}
 
Example #23
Source File: Docx4j_创建批注_S3_Test.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public void createCommentEnd(ObjectFactory factory, P p, String pContent,  
        String commentContent, RPr fontRPr, RPr commentRPr,  
        BigInteger commentId, Comments comments) throws Exception{  
    Text txt = factory.createText();  
    txt.setValue(pContent);  
    R run = factory.createR();  
    run.getContent().add(txt);  
    run.setRPr(fontRPr);  
    p.getContent().add(run);  
    Comment commentOne = createComment(factory, commentId, "系统管理员",new Date(), commentContent, commentRPr);  
    comments.getComment().add(commentOne);  
    p.getContent().add(createRunCommentReference(factory, commentId));  
}
 
Example #24
Source File: Docx4j_创建批注_S3_Test.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public void testCreateComment(WordprocessingMLPackage wordMLPackage,  
        MainDocumentPart t, ObjectFactory factory) throws Exception {  
    P p = factory.createP();  
    setParagraphSpacing(factory, p, true, "0",  
            "0",true, null, "100", true, "240", STLineSpacingRule.AUTO);  
    t.addObject(p);  
    RPr fontRPr = getRPrStyle(factory, "微软雅黑", "000000", "20",  
            STHint.EAST_ASIA, false, false, false, true, UnderlineEnumeration.SINGLE,  "B61CD2",  
            true, "darkYellow", false, null, null, null);  
    RPr commentRPr = getRPrStyle(factory, "微软雅黑", "41A62D", "18",  
            STHint.EAST_ASIA, true, true, false, false, null, null, false,  
            null, false, null, null, null);  
    Comments comments = addDocumentCommentsPart(wordMLPackage, factory);  
    BigInteger commentId = BigInteger.valueOf(1);  
      
    createCommentEnd(factory, p, "测试", "这是官网Demo", fontRPr, commentRPr, commentId, comments);  
    commentId = commentId.add(BigInteger.ONE);  
  
    createCommentRound(factory, p, "批注", "这是批注comment", fontRPr, commentRPr, commentId, comments);  
    commentId = commentId.add(BigInteger.ONE);  
      
    p = factory.createP();  
    setParagraphSpacing(factory, p, true, "0",  
            "0",true, null, "100", true, "240", STLineSpacingRule.AUTO);  
    t.addObject(p);  
    createCommentRound(factory, p, "批注2", "这是批注comment2", fontRPr, commentRPr, commentId, comments);  
    commentId = commentId.add(BigInteger.ONE);  
      
    createCommentEnd(factory, p, "测试2", "这是官网Demo", fontRPr, commentRPr, commentId, comments);  
    commentId = commentId.add(BigInteger.ONE);  
}
 
Example #25
Source File: Docx4J_简单例子2.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public P createImageParagraph(WordprocessingMLPackage wordMLPackage,  
        ObjectFactory factory,P p,String fileName, String content,byte[] bytes,  
        JcEnumeration jcEnumeration) throws Exception {  
    BinaryPartAbstractImage imagePart = BinaryPartAbstractImage  
            .createImagePart(wordMLPackage, bytes);  
    Inline inline = imagePart.createImageInline(fileName, "这是图片", 1,  
            2, false);  
    Text text = factory.createText();  
    text.setValue(content);  
    text.setSpace("preserve");  
    R run = factory.createR();  
    p.getContent().add(run);  
    run.getContent().add(text);  
    Drawing drawing = factory.createDrawing();  
    run.getContent().add(drawing);  
    drawing.getAnchorOrInline().add(inline);  
    PPr pPr = p.getPPr();  
    if (pPr == null) {  
        pPr = factory.createPPr();  
    }  
    Jc jc = pPr.getJc();  
    if (jc == null) {  
        jc = new Jc();  
    }  
    jc.setVal(jcEnumeration);  
    pPr.setJc(jc);  
    p.setPPr(pPr);  
    setParagraphSpacing(factory, p, jcEnumeration, "0", "0");  
    return p;  
}
 
Example #26
Source File: Docx4J_简单例子.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public Ftr getFtr(WordprocessingMLPackage wordprocessingMLPackage,
		ObjectFactory factory, Part sourcePart) throws Exception {
	Ftr ftr = factory.createFtr();
	File file = new File("f:/saveFile/tmp/xxt.jpg");
	java.io.InputStream is = new java.io.FileInputStream(file);
	ftr.getContent().add(
			newImage(wordprocessingMLPackage, factory, sourcePart,
					BufferUtil.getBytesFromInputStream(is), "filename",
					"这是页脚", 1, 2, JcEnumeration.CENTER));
	return ftr;
}
 
Example #27
Source File: Docx4J_简单例子2.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public Relationship createHeaderPart(  
        WordprocessingMLPackage wordprocessingMLPackage,  
        MainDocumentPart t, ObjectFactory factory) throws Exception {  
    HeaderPart headerPart = new HeaderPart();  
    Relationship rel = t.addTargetPart(headerPart);  
    // After addTargetPart, so image can be added properly  
    headerPart.setJaxbElement(getHdr(wordprocessingMLPackage, factory,  
            headerPart));  
    return rel;  
}
 
Example #28
Source File: Docx4j_创建批注_S3_Test.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public void setParagraphShdStyle(ObjectFactory factory, P p, boolean isShd,  
        STShd shdValue, String shdColor) {  
    if (isShd) {  
        PPr ppr = factory.createPPr();  
        CTShd shd = new CTShd();  
        if (shdColor != null) {  
            shd.setColor(shdColor);  
        }  
        if (shdValue != null) {  
            shd.setVal(shdValue);  
        }  
        ppr.setShd(shd);  
        p.setPPr(ppr);  
    }  
}
 
Example #29
Source File: Docx4J_简单例子2.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public Relationship createFooterPageNumPart(  
        WordprocessingMLPackage wordprocessingMLPackage,  
        MainDocumentPart t, ObjectFactory factory) throws Exception {  
    FooterPart footerPart = new FooterPart();  
    footerPart.setPackage(wordprocessingMLPackage);  
    footerPart.setJaxbElement(createFooterWithPageNr(factory));  
    return t.addTargetPart(footerPart);  
}
 
Example #30
Source File: Docx4j_创建批注_S3_Test.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public R createRunCommentReference(ObjectFactory factory,  
        BigInteger commentId) {  
    R run = factory.createR();  
    R.CommentReference commentRef = factory.createRCommentReference();  
    run.getContent().add(commentRef);  
    commentRef.setId(commentId);  
    return run;  
}