org.docx4j.wml.Text Java Examples

The following examples show how to use org.docx4j.wml.Text. 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: TextMerger.java    From yarg with Apache License 2.0 6 votes vote down vote up
protected void handleMatchedText() {
    resultingTexts.add(startText);
    startText.setValue(mergedTextsString.toString());
    for (Text mergedText : mergedTexts) {
        if (mergedText != startText) {
            mergedText.setValue("");
            textsToRemove.add(mergedText);
        }
    }

    if (!containsStartOfRegexp(startText.getValue().replaceAll(regexp, ""))) {
        startText = null;
        mergedTexts = null;
        mergedTextsString = null;
    } else {
        mergedTexts = new HashSet<Text>();
        mergedTexts.add(startText);
        mergedTextsString = new StringBuilder(startText.getValue());
    }
}
 
Example #2
Source File: AbstractInliner.java    From yarg with Apache License 2.0 6 votes vote down vote up
protected Part resolveTextPartForDOCX(Text text, WordprocessingMLPackage wordPackage) {
    java.util.List<SectionWrapper> sectionWrappers = wordPackage.getDocumentModel().getSections();
    for (SectionWrapper sw : sectionWrappers) {
        HeaderFooterPolicy hfp = sw.getHeaderFooterPolicy();
        List<Part> parts = Arrays.asList(hfp.getFirstHeader(), hfp.getDefaultHeader(), hfp.getEvenHeader(),
                hfp.getFirstFooter(), hfp.getDefaultFooter(), hfp.getEvenFooter());
        for (Part part : parts) {
            TextMatchCallback callback = new TextMatchCallback(text);
            new TraversalUtil(part, callback);
            if (callback.matched) {
                return part;
            }
        }
    }
    return wordPackage.getMainDocumentPart();
}
 
Example #3
Source File: TableWithStyledContent.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
/**
 *  这里我们添加实际的样式信息, 首先创建一个段落, 然后创建以单元格内容作为值的文本对象; 
 *  第三步, 创建一个被称为运行块的对象, 它是一块或多块拥有共同属性的文本的容器, 并将文本对象添加
 *  到其中. 随后我们将运行块R添加到段落内容中.
 *  直到现在我们所做的还没有添加任何样式, 为了达到目标, 我们创建运行块属性对象并给它添加各种样式.
 *  这些运行块的属性随后被添加到运行块. 最后段落被添加到表格的单元格中.
 */
private static void addStyling(Tc tableCell, String content, boolean bold, String fontSize) {
    P paragraph = factory.createP();
 
    Text text = factory.createText();
    text.setValue(content);
 
    R run = factory.createR();
    run.getContent().add(text);
 
    paragraph.getContent().add(run);
 
    RPr runProperties = factory.createRPr();
    if (bold) {
        addBoldStyle(runProperties);
    }
 
    if (fontSize != null && !fontSize.isEmpty()) {
        setFontSize(runProperties, fontSize);
    }
 
    run.setRPr(runProperties);
 
    tableCell.getContent().add(paragraph);
}
 
Example #4
Source File: Docx4J_简单例子2.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 #5
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 #6
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 #7
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 #8
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 #9
Source File: DocxBuilder.java    From TranskribusCore with GNU General Public License v3.0 6 votes vote down vote up
private void getFormattedTextForLineElement(List<WordType> words, P p, MainDocumentPart mdp) throws Exception{
	
	int wordCount = 0;
	int nrWords = words.size();
	
	for (WordType word : words){
		getFormattedTextForShapeElement((ITrpShapeType) word, p, mdp);
		//add empty space after each word
		if (wordCount < nrWords-1){
			org.docx4j.wml.Text  t = factory.createText();
			t.setValue(" ");
			t.setSpace("preserve");
			
			org.docx4j.wml.R  run = factory.createR();
			p.getContent().add(run);
			run.getContent().add(t);
		}
		wordCount++;
	}

}
 
Example #10
Source File: DocxBuilder.java    From TranskribusCore with GNU General Public License v3.0 6 votes vote down vote up
private org.docx4j.wml.Comments.Comment createComment(java.math.BigInteger commentId,
    		String author, Calendar date, String message) {

		org.docx4j.wml.Comments.Comment comment = factory.createCommentsComment();
		comment.setId( commentId );
		if (author!=null) {
			comment.setAuthor(author);
		}
		if (date!=null) {
//			String dateString = RFC3339_FORMAT.format(date.getTime()) ;	
//			comment.setDate(value)
			// TODO - at present this is XMLGregorianCalendar
		}
		org.docx4j.wml.P commentP = factory.createP();
		comment.getEGBlockLevelElts().add(commentP);
		org.docx4j.wml.R commentR = factory.createR();
		commentP.getContent().add(commentR);
		org.docx4j.wml.Text commentText = factory.createText();
		commentR.getContent().add(commentText);
		
		commentText.setValue(message);
    	
    	return comment;
    }
 
Example #11
Source File: TextMerger.java    From yarg with Apache License 2.0 6 votes vote down vote up
public Set<Text> mergeMatchedTexts() {
    for (Object paragraphContentObject : paragraph.getContent()) {
        if (paragraphContentObject instanceof R) {
            R currentRun = (R) paragraphContentObject;
            for (Object runContentObject : currentRun.getContent()) {
                Object unwrappedRunContentObject = XmlUtils.unwrap(runContentObject);
                if (unwrappedRunContentObject instanceof Text) {
                    handleText((Text) unwrappedRunContentObject);
                }
            }
        }
    }

    removeUnnecessaryTexts();

    return resultingTexts;
}
 
Example #12
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 #13
Source File: WordprocessingMLPackageRender.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
public void addStyling(Tc tableCell, String content, boolean bold, String fontSize) {  
    P paragraph = factory.createP();  
   
    Text text = factory.createText();  
    text.setValue(content);  
   
    R run = factory.createR();  
    run.getContent().add(text);  
   
    paragraph.getContent().add(run);  
   
    RPr runProperties = factory.createRPr();  
    if (bold) {  
        addBoldStyle(runProperties);  
    }  
   
    if (fontSize != null && !fontSize.isEmpty()) {  
        setFontSize(runProperties, fontSize);  
    }  
   
    run.setRPr(runProperties);  
   
    tableCell.getContent().add(paragraph);  
}
 
Example #14
Source File: WmlElementUtils.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
/**
 * @Description: 添加图片到段落
 */
public static 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 #15
Source File: Docx4j_替换模板.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
/** 
 * 设置单元格内容 
 *  
 * @param tc 
 * @param content 
 */  
public static void setNewTcContent(Tc tc, String content) {  
    P p = factory.createP();  
    tc.getContent().add(p);  
    R run = factory.createR();  
    p.getContent().add(run);  
    if (content != null) {  
        String[] contentArr = content.split("\n");  
        Text text = factory.createText();  
        text.setSpace("preserve");  
        text.setValue(contentArr[0]);  
        run.getContent().add(text);  
  
        for (int i = 1, len = contentArr.length; i < len; i++) {  
            Br br = factory.createBr();  
            run.getContent().add(br);// 换行  
            text = factory.createText();  
            text.setSpace("preserve");  
            text.setValue(contentArr[i]);  
            run.getContent().add(text);  
        }  
    }  
}
 
Example #16
Source File: TextMerger.java    From yarg with Apache License 2.0 5 votes vote down vote up
protected void removeUnnecessaryTexts() {
    for (Text text : textsToRemove) {
        Object parent = XmlUtils.unwrap(text.getParent());
        if (parent instanceof R) {
            ((R) parent).getContent().remove(text);
        }
    }
}
 
Example #17
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 #18
Source File: Docx4J_简单例子2.java    From docx4j-template with Apache License 2.0 5 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);  
      
    PBdr pBdr=pPr.getPBdr();  
    if(pBdr==null){  
        pBdr=factory.createPPrBasePBdr();  
    }  
      
    CTBorder value=new CTBorder();  
    value.setVal(STBorder.SINGLE);  
    value.setColor("000000");  
    value.setSpace(new BigInteger("0"));  
    value.setSz(new BigInteger("3"));  
    pBdr.setBetween(value);  
    pPr.setPBdr(pBdr);  
    headP.setPPr(pPr);  
    setParagraphSpacing(factory, headP, jcEnumeration, "0", "0");  
    hdr.getContent().add(headP);  
    hdr.getContent().add(createHeaderBlankP(wordprocessingMLPackage, factory, jcEnumeration));  
    return hdr;  
}
 
Example #19
Source File: TableManager.java    From yarg with Apache License 2.0 5 votes vote down vote up
TableManager(DocxFormatterDelegate docxFormatter, Tbl tbl) {
    this.docxFormatter = docxFormatter;
    this.table = tbl;
    INVARIANTS_SETTER = new AliasVisitor(docxFormatter) {
        @Override
        protected void handle(Text text) {

        }
    };
}
 
Example #20
Source File: TextMerger.java    From yarg with Apache License 2.0 5 votes vote down vote up
protected void handleText(Text currentText) {
    if (startText == null && containsStartOfRegexp(currentText.getValue())) {
        initMergeQueue(currentText);
    }

    if (startText != null) {
        addToMergeQueue(currentText);

        if (mergeQueueMatchesRegexp()) {
            handleMatchedText();
        }
    }
}
 
Example #21
Source File: Docx4j_创建表格_S5_Test.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public void addCellStyle(ObjectFactory factory, Tc tableCell,  
        String content, Docx4jStyle_S3 style) {  
    if (style != null) {  
        P paragraph = factory.createP();  
        Text text = factory.createText();  
        text.setValue(content);  
        R run = factory.createR();  
        run.getContent().add(text);  
        paragraph.getContent().add(run);  
        setHorizontalAlignment(paragraph, style.getHorizAlignment());  
        RPr runProperties = factory.createRPr();  
        if (style.isBold()) {  
            addBoldStyle(runProperties);  
        }  
        if (style.isItalic()) {  
            addItalicStyle(runProperties);  
        }  
        if (style.isUnderline()) {  
            addUnderlineStyle(runProperties);  
        }  
        setFontSize(runProperties, style.getFontSize());  
        setFontColor(runProperties, style.getFontColor());  
        setFontFamily(runProperties, style.getCnFontFamily(),style.getEnFontFamily());  
        setCellMargins(tableCell, style.getTop(), style.getRight(),  
                style.getBottom(), style.getLeft());  
        setCellColor(tableCell, style.getBackground());  
        setVerticalAlignment(tableCell, style.getVerticalAlignment());  
        setCellBorders(tableCell, style.isBorderTop(),  
                style.isBorderRight(), style.isBorderBottom(),  
                style.isBorderLeft());  
        run.setRPr(runProperties);  
        tableCell.getContent().add(paragraph);  
    }  
}
 
Example #22
Source File: AbstractInliner.java    From yarg with Apache License 2.0 5 votes vote down vote up
@Override
public void inlineToDocx(WordprocessingMLPackage wordPackage, Text text, Object paramValue, Matcher paramsMatcher) {
    try {
        Image image = new Image(paramValue, paramsMatcher);
        if (image.isValid()) {
            Part part = resolveTextPartForDOCX(text, wordPackage);
            BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordPackage, part, image.imageContent);
            int originalWidth = imagePart.getImageInfo().getSize().getWidthPx();
            int originalHeight = imagePart.getImageInfo().getSize().getHeightPx();

            double widthScale = (double) image.width / (double) originalWidth;
            double heightScale = (double) image.height  / (double) originalHeight;
            double actualScale = Math.min(widthScale, heightScale);

            long targetWidth = Math.round(originalWidth * actualScale);
            long targetHeight = Math.round(originalHeight * actualScale);

            Inline inline = imagePart.createImageInline("", "", docxUniqueId1++, docxUniqueId2++,
                    XlsxUtils.convertPxToEmu(targetWidth), XlsxUtils.convertPxToEmu(targetHeight), false);

            org.docx4j.wml.Drawing drawing = new org.docx4j.wml.ObjectFactory().createDrawing();
            R run = (R) text.getParent();
            run.getContent().add(drawing);
            drawing.getAnchorOrInline().add(inline);
            text.setValue("");
        }
    } catch (Exception e) {
        throw new ReportFormattingException("An error occurred while inserting bitmap to docx file", e);
    }
}
 
Example #23
Source File: Docx4J_简单例子.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public void addTableCell(ObjectFactory factory,
		WordprocessingMLPackage wordMLPackage, Tr tableRow, String content,
		RPr rpr, JcEnumeration jcEnumeration, boolean hasBgColor,
		String backgroudColor) {
	Tc tableCell = factory.createTc();
	P p = factory.createP();
	setParagraphAlign(factory, p, jcEnumeration);
	Text t = factory.createText();
	t.setValue(content);
	R run = factory.createR();
	// 设置表格内容字体样式
	run.setRPr(rpr);
	run.getContent().add(t);
	p.getContent().add(run);
	tableCell.getContent().add(p);

	if (hasBgColor) {
		TcPr tcPr = tableCell.getTcPr();
		if (tcPr == null) {
			tcPr = factory.createTcPr();
		}
		CTShd shd = tcPr.getShd();
		if (shd == null) {
			shd = factory.createCTShd();
		}
		shd.setColor("auto");
		shd.setFill(backgroudColor);
		tcPr.setShd(shd);
		tableCell.setTcPr(tcPr);
	}
	tableRow.getContent().add(tableCell);
}
 
Example #24
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 #25
Source File: Docx4J_简单例子.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public void addTotalPageNumberField(ObjectFactory factory, P paragraph) {
	R run = factory.createR();
	Text txt = new Text();
	txt.setSpace("preserve");
	txt.setValue("NUMPAGES  \\* MERGEFORMAT ");
	run.getContent().add(factory.createRInstrText(txt));
	paragraph.getContent().add(run);
}
 
Example #26
Source File: Docx4J_简单例子.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
private void addPageTextField(ObjectFactory factory, P paragraph,
		String value) {
	R run = factory.createR();
	Text txt = new Text();
	txt.setSpace("preserve");
	txt.setValue(value);
	run.getContent().add(txt);
	paragraph.getContent().add(run);
}
 
Example #27
Source File: AliasVisitor.java    From yarg with Apache License 2.0 5 votes vote down vote up
@Override
public List<Object> apply(Object o) {
    if (o instanceof P || o instanceof P.Hyperlink) {
        String paragraphText = docxFormatter.getElementText(o);

        if (AbstractFormatter.UNIVERSAL_ALIAS_PATTERN.matcher(paragraphText).find()) {
            Set<Text> mergedTexts = new TextMerger((ContentAccessor) o, AbstractFormatter.UNIVERSAL_ALIAS_REGEXP).mergeMatchedTexts();
            for (Text text : mergedTexts) {
                handle(text);
            }
        }
    }

    return null;
}
 
Example #28
Source File: TextBoxTest.java    From docx4j-export-FO with Apache License 2.0 5 votes vote down vote up
private static R addFiller() {
	

    R r = Context.getWmlObjectFactory().createR(); 
        // Create object for t (wrapped in JAXBElement) 
        Text text = Context.getWmlObjectFactory().createText(); 
        JAXBElement<org.docx4j.wml.Text> textWrapped = Context.getWmlObjectFactory().createRT(text); 
        r.getContent().add( textWrapped); 
            text.setValue( "The cat sat on the mat. The cat sat on the mat. The cat sat on the mat. The cat sat on the mat. The cat sat on the mat. The cat sat on the mat. The cat sat on the mat. The cat sat on the mat. The cat sat on the mat. The cat sat on the mat. The cat sat on the mat. The cat sat on the mat. The cat sat on the mat. The cat sat on the mat. The cat sat on the mat. The cat sat on the mat. The cat sat on the mat. The cat sat on the mat. The cat sat on the mat. The cat sat on the mat. The cat sat on the mat. "); 
            
            return r;
}
 
Example #29
Source File: FOPAreaTreeHelper.java    From docx4j-export-FO with Apache License 2.0 5 votes vote down vote up
private static P createFillerP() {

    	org.docx4j.wml.ObjectFactory wmlObjectFactory = Context.getWmlObjectFactory();

    	P p = wmlObjectFactory.createP(); 
    	    // Create object for pPr
    	    PPr ppr = wmlObjectFactory.createPPr(); 
    	    p.setPPr(ppr); 
    	        // Create object for rPr
    	        ParaRPr pararpr = wmlObjectFactory.createParaRPr(); 

    	        // Create object for spacing
    	        PPrBase.Spacing pprbasespacing = wmlObjectFactory.createPPrBaseSpacing(); 
    	        ppr.setSpacing(pprbasespacing); 
    	            pprbasespacing.setBefore( BigInteger.valueOf( 800) ); 
    	            pprbasespacing.setAfter( BigInteger.valueOf( 800) ); 
    	    // Create object for r
    	    R r = wmlObjectFactory.createR(); 
    	    p.getContent().add( r); 
    	        // Create object for rPr
    	        RPr rpr = wmlObjectFactory.createRPr(); 
    	        r.setRPr(rpr); 
    	            // Create object for sz
    	            HpsMeasure hpsmeasure3 = wmlObjectFactory.createHpsMeasure(); 
    	            rpr.setSz(hpsmeasure3); 
    	                hpsmeasure3.setVal( BigInteger.valueOf( 96) ); 

    	        // Create object for t (wrapped in JAXBElement) 
    	        Text text = wmlObjectFactory.createText(); 
    	        JAXBElement<org.docx4j.wml.Text> textWrapped = wmlObjectFactory.createRT(text); 
    	        r.getContent().add( textWrapped); 
    	            text.setValue( "BODY CONTENT"); 

    	return p;
    }
 
Example #30
Source File: TextBoxTest.java    From docx4j-export-FO with Apache License 2.0 5 votes vote down vote up
private static P createContent(String textContent) {
	
	P p = Context.getWmlObjectFactory().createP(); 

    R r = Context.getWmlObjectFactory().createR(); 
    p.getContent().add( r); 
        // Create object for t (wrapped in JAXBElement) 
        Text text = Context.getWmlObjectFactory().createText(); 
        JAXBElement<org.docx4j.wml.Text> textWrapped = Context.getWmlObjectFactory().createRT(text); 
        r.getContent().add( textWrapped); 
            text.setValue( textContent); 
            
            return p;
}