Java Code Examples for org.docx4j.wml.R#setRPr()
The following examples show how to use
org.docx4j.wml.R#setRPr() .
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: WordprocessingMLPackageRender.java From docx4j-template with Apache License 2.0 | 6 votes |
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 2
Source File: Docx4j_工具类_S3_Test.java From docx4j-template with Apache License 2.0 | 6 votes |
/** * @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 3
Source File: WmlElementUtils.java From docx4j-template with Apache License 2.0 | 6 votes |
/** * @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 4
Source File: Docx4J_简单例子.java From docx4j-template with Apache License 2.0 | 6 votes |
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 5
Source File: Docx4j_创建批注_S3_Test.java From docx4j-template with Apache License 2.0 | 6 votes |
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 6
Source File: Docx4j_创建批注_S3_Test.java From docx4j-template with Apache License 2.0 | 6 votes |
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 7
Source File: TableWithStyledContent.java From docx4j-template with Apache License 2.0 | 6 votes |
/** * 这里我们添加实际的样式信息, 首先创建一个段落, 然后创建以单元格内容作为值的文本对象; * 第三步, 创建一个被称为运行块的对象, 它是一块或多块拥有共同属性的文本的容器, 并将文本对象添加 * 到其中. 随后我们将运行块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 8
Source File: Docx4J_简单例子2.java From docx4j-template with Apache License 2.0 | 6 votes |
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 9
Source File: FOPAreaTreeHelper.java From docx4j-export-FO with Apache License 2.0 | 5 votes |
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 10
Source File: Docx4J_简单例子.java From docx4j-template with Apache License 2.0 | 5 votes |
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 11
Source File: Docx4j_创建表格_S5_Test.java From docx4j-template with Apache License 2.0 | 5 votes |
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 12
Source File: Docx4j_创建批注_S3_Test.java From docx4j-template with Apache License 2.0 | 5 votes |
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 13
Source File: Docx4J_例子2.java From docx4j-template with Apache License 2.0 | 5 votes |
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(); setParagraphSpacing(factory, p, jcEnumeration, true, "0", "0", null, null, true, "240", STLineSpacingRule.AUTO); Text t = factory.createText(); t.setValue(content); R run = factory.createR(); // 设置表格内容字体样式 run.setRPr(rpr); TcPr tcPr = tableCell.getTcPr(); if (tcPr == null) { tcPr = factory.createTcPr(); } CTVerticalJc valign = factory.createCTVerticalJc(); valign.setVal(STVerticalJc.CENTER); tcPr.setVAlign(valign); run.getContent().add(t); p.getContent().add(run); tableCell.getContent().add(p); if (hasBgColor) { 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 14
Source File: Docx4j_Helper.java From docx4j-template with Apache License 2.0 | 5 votes |
/** * 设置段落内容 */ private static void setParagraphContent(P p, RPr rpr,String content) { Text t = Docx4j_Helper.factory.createText(); t.setSpace("preserve"); t.setValue(content); R run = Docx4j_Helper.factory.createR(); run.setRPr(rpr); run.getContent().add(t); p.getContent().add(run); }
Example 15
Source File: Docx4J_简单例子2.java From docx4j-template with Apache License 2.0 | 4 votes |
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); TcPr tcPr = tableCell.getTcPr(); if (tcPr == null) { tcPr = factory.createTcPr(); } CTVerticalJc valign = factory.createCTVerticalJc(); valign.setVal(STVerticalJc.CENTER); tcPr.setVAlign(valign); run.getContent().add(t); p.getContent().add(run); PPr ppr=p.getPPr(); if(ppr==null){ ppr=factory.createPPr(); } //设置段后距离 Spacing spacing=new Spacing(); spacing.setAfter(new BigInteger("0")); spacing.setLineRule(STLineSpacingRule.AUTO); ppr.setSpacing(spacing); p.setPPr(ppr); tableCell.getContent().add(p); if (hasBgColor) { 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 16
Source File: Docx4J_简单例子.java From docx4j-template with Apache License 2.0 | 4 votes |
public void addParagraphTest(WordprocessingMLPackage wordMLPackage, MainDocumentPart t, ObjectFactory factory) throws Exception { RPr titleRPr = getRPr(factory, "黑体", "000000", "28", STHint.EAST_ASIA, true, false, false, false); RPr boldRPr = getRPr(factory, "宋体", "000000", "22", STHint.EAST_ASIA, true, false, false, false); RPr fontRPr = getRPr(factory, "宋体", "000000", "20", STHint.EAST_ASIA, false, false, false, false); P paragraph = factory.createP(); setParagraphAlign(factory, paragraph, JcEnumeration.CENTER); Text txt = factory.createText(); txt.setValue("七年级上册Unit2 This is just a test. sectionA测试卷答题卡"); R run = factory.createR(); run.getContent().add(txt); run.setRPr(titleRPr); paragraph.getContent().add(run); t.addObject(paragraph); paragraph = factory.createP(); setParagraphAlign(factory, paragraph, JcEnumeration.CENTER); txt = factory.createText(); txt.setValue("班级:________ 姓名:________"); run = factory.createR(); run.getContent().add(txt); run.setRPr(fontRPr); paragraph.getContent().add(run); t.addObject(paragraph); paragraph = factory.createP(); txt = factory.createText(); txt.setValue("一、单选题"); run = factory.createR(); run.getContent().add(txt); run.setRPr(boldRPr); paragraph.getContent().add(run); t.addObject(paragraph); paragraph = factory.createP(); txt = factory.createText(); txt.setValue("1.下列有关仪器用途的说法错误的是( )"); run = factory.createR(); run.getContent().add(txt); run.setRPr(fontRPr); paragraph.getContent().add(run); t.addObject(paragraph); paragraph = factory.createP(); txt = factory.createText(); txt.setValue("A.烧杯用于较多量试剂的反应容器"); run = factory.createR(); run.getContent().add(txt); run.setRPr(fontRPr); paragraph.getContent().add(run); t.addObject(paragraph); paragraph = factory.createP(); txt = factory.createText(); txt.setValue("B.烧杯用于较多量试剂的反应容器"); run = factory.createR(); run.getContent().add(txt); run.setRPr(fontRPr); paragraph.getContent().add(run); t.addObject(paragraph); paragraph = factory.createP(); txt = factory.createText(); txt.setValue("C.烧杯用于较多量试剂的反应容器"); run = factory.createR(); run.getContent().add(txt); run.setRPr(fontRPr); paragraph.getContent().add(run); t.addObject(paragraph); paragraph = factory.createP(); txt = factory.createText(); txt.setValue("D.烧杯用于较多量试剂的反应容器"); run = factory.createR(); run.getContent().add(txt); run.setRPr(fontRPr); paragraph.getContent().add(run); t.addObject(paragraph); }
Example 17
Source File: Docx4J_例子2.java From docx4j-template with Apache License 2.0 | 4 votes |
public Ftr createFooterWithPageNr( WordprocessingMLPackage wordprocessingMLPackage, ObjectFactory factory, boolean isUnderLine, String underLineSz, JcEnumeration jcEnumeration) throws Exception { 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, "页"); setParagraphSpacing(factory, paragraph, jcEnumeration, true, "0", "0", null, null, true, "240", STLineSpacingRule.AUTO); PPr pPr = paragraph.getPPr(); if (pPr == null) { pPr = factory.createPPr(); } Jc jc = pPr.getJc(); if (jc == null) { jc = new Jc(); } jc.setVal(jcEnumeration); pPr.setJc(jc); if (isUnderLine) { 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(underLineSz)); pBdr.setBetween(value); pPr.setPBdr(pBdr); paragraph.setPPr(pPr); } ftr.getContent().add(paragraph); if (isUnderLine) { ftr.getContent().add( createHeaderBlankP(wordprocessingMLPackage, factory, underLineSz, jcEnumeration)); } return ftr; }
Example 18
Source File: DocxBuilder.java From TranskribusCore with GNU General Public License v3.0 | 4 votes |
public void addFootnote(int i, String text, FootnotesPart footnotesPart, R r) throws JAXBException, Docx4JException { // Add the note number in the run CTFtnEdnRef ftnednref = factory.createCTFtnEdnRef(); JAXBElement<org.docx4j.wml.CTFtnEdnRef> ftnednrefWrapped = factory.createRFootnoteReference(ftnednref); r.getContent().add( ftnednrefWrapped); ftnednref.setId( BigInteger.valueOf(i) ); //escape the special chars for XML String escapedText = StringEscapeUtils.escapeXml(text); /* * Test: try to set footnote reference */ org.docx4j.wml.RPr props = factory.createRPr(); RStyle rStyle = new RStyle(); rStyle.setVal("FootnoteReference"); props.setRStyle(rStyle); r.setRPr(props); // Create a footnote in the footnotesPart String openXML = "<w:footnote w:id=\"" + i + "\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\">" + "<w:p>" + "<w:pPr>" + "<w:pStyle w:val=\"FootnoteText\"/>" + "<w:rPr>" + "<w:lang w:val=\"en-AU\"/>" +"</w:rPr>" +"</w:pPr>" + "<w:r>" + "<w:rPr>" + "<w:rStyle w:val=\"FootnoteReference\"/>" + "<w:vertAlign w:val=\"superscript\" />" +"</w:rPr>" + "<w:footnoteRef/>" +"</w:r>" + "<w:r>" + "<w:t xml:space=\"preserve\"> </w:t>" +"</w:r>" + "<w:r>" + "<w:rPr>" + "<w:lang w:val=\"en-AU\"/>" +"</w:rPr>" + "<w:t>" + escapedText +"</w:t>" +"</w:r>" +"</w:p>" +"</w:footnote>"; CTFtnEdn ftnedn = (CTFtnEdn)XmlUtils.unmarshalString(openXML, Context.jc, CTFtnEdn.class); footnotesPart.getContents().getFootnote().add(ftnedn); }
Example 19
Source File: DocxBuilder.java From TranskribusCore with GNU General Public License v3.0 | 4 votes |
public P createIt() { org.docx4j.wml.ObjectFactory wmlObjectFactory = new org.docx4j.wml.ObjectFactory(); P p = wmlObjectFactory.createP(); // Create object for pPr PPr ppr = wmlObjectFactory.createPPr(); p.setPPr(ppr); // Create object for rPr ParaRPr pararpr = wmlObjectFactory.createParaRPr(); ppr.setRPr(pararpr); // Create object for u U u = wmlObjectFactory.createU(); pararpr.setU(u); u.setVal(org.docx4j.wml.UnderlineEnumeration.SINGLE); // Create object for lang CTLanguage language = wmlObjectFactory.createCTLanguage(); pararpr.setLang(language); language.setVal( "en-AU"); // Create object for jc Jc jc = wmlObjectFactory.createJc(); ppr.setJc(jc); jc.setVal(org.docx4j.wml.JcEnumeration.CENTER); // 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 u U u2 = wmlObjectFactory.createU(); rpr.setU(u2); u2.setVal(org.docx4j.wml.UnderlineEnumeration.SINGLE); // Create object for lang CTLanguage language2 = wmlObjectFactory.createCTLanguage(); rpr.setLang(language2); language2.setVal( "en-AU"); // 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( "Underlined and centred"); return p; }