org.docx4j.wml.R Java Examples
The following examples show how to use
org.docx4j.wml.R.
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 | 6 votes |
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 #2
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 #3
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 #4
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 #5
Source File: TextMerger.java From yarg with Apache License 2.0 | 6 votes |
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 #6
Source File: Docx4j_创建表格_S5_Test.java From docx4j-template with Apache License 2.0 | 6 votes |
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 #7
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 #8
Source File: Docx4J_简单例子.java From docx4j-template with Apache License 2.0 | 6 votes |
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 #9
Source File: Docx4J_简单例子.java From docx4j-template with Apache License 2.0 | 6 votes |
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 #10
Source File: DocxBuilder.java From TranskribusCore with GNU General Public License v3.0 | 6 votes |
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 #11
Source File: DocxBuilder.java From TranskribusCore with GNU General Public License v3.0 | 6 votes |
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 #12
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 #13
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 #14
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 #15
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 #16
Source File: WmlElementUtils.java From docx4j-template with Apache License 2.0 | 6 votes |
/** * @Description: 隐藏单元格内容 */ public static void setTcHidden(Tc tc, boolean hidden) { List<P> pList = getTcAllP(tc); for (P p : pList) { PPr ppr = getPPr(p); List<Object> objRList = getAllElementFromObject(p, R.class); if (objRList == null) { continue; } for (Object objR : objRList) { if (objR instanceof R) { R r = (R) objR; RPr rpr = getRPr(r); setRPrVanishStyle(rpr, hidden); } } setParaVanish(ppr, hidden); } }
Example #17
Source File: WmlElementUtils.java From docx4j-template with Apache License 2.0 | 6 votes |
/** * 插入图片 * @param wPackage * @param bm * @param file * @throws Exception */ public static void addImage(WordprocessingMLPackage wPackage, CTBookmark bm, String file) throws Exception { // 这儿可以对单个书签进行操作,也可以用一个map对所有的书签进行处理 // 获取该书签的父级段落 P p = (P) (bm.getParent()); // R对象是匿名的复杂类型,然而我并不知道具体啥意思,估计这个要好好去看看ooxml才知道 R run = factory.createR(); // 读入图片并转化为字节数组,因为docx4j只能字节数组的方式插入图片 byte[] bytes = null;//FileUtil.getByteFormBase64DataByImage(file); // InputStream is = new FileInputStream; // byte[] bytes = IOUtils.toByteArray(inputStream); // byte[] bytes = FileUtil.getByteFormBase64DataByImage(""); // 开始创建一个行内图片 BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wPackage, bytes); // createImageInline函数的前四个参数我都没有找到具体啥意思,,,, // 最有一个是限制图片的宽度,缩放的依据 Inline inline = imagePart.createImageInline(null, null, 0, 1, false, 0); // 获取该书签的父级段落 // drawing理解为画布? Drawing drawing = factory.createDrawing(); drawing.getAnchorOrInline().add(inline); run.getContent().add(drawing); p.getContent().add(run); }
Example #18
Source File: Docx4J_简单例子.java From docx4j-template with Apache License 2.0 | 5 votes |
public P newImage(WordprocessingMLPackage wordMLPackage, ObjectFactory factory, Part sourcePart, byte[] bytes, String filenameHint, String altText, int id1, int id2, JcEnumeration jcEnumeration) throws Exception { BinaryPartAbstractImage imagePart = BinaryPartAbstractImage .createImagePart(wordMLPackage, sourcePart, bytes); Inline inline = imagePart.createImageInline(filenameHint, altText, id1, id2, false); P p = factory.createP(); R run = factory.createR(); p.getContent().add(run); 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); return p; }
Example #19
Source File: TextBoxTest.java From docx4j-export-FO with Apache License 2.0 | 5 votes |
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 #20
Source File: ImageReplacementInGlobalParagraphsTest.java From docx-stamper with MIT License | 5 votes |
@Test public void testWithMaxWidth() throws Docx4JException, IOException { Image monalisa = new Image(getClass().getResourceAsStream("monalisa.jpg"), 1000); ImageContext context = new ImageContext(); context.setMonalisa(monalisa); InputStream template = getClass().getResourceAsStream("ImageReplacementInGlobalParagraphsTest.docx"); WordprocessingMLPackage document = stampAndLoad(template, context); Assert.assertTrue(((JAXBElement) ((R) ((P) document.getMainDocumentPart().getContent().get(2)).getContent().get(1)).getContent().get(0)).getValue() instanceof Drawing); Assert.assertTrue(((JAXBElement) ((R) ((P) document.getMainDocumentPart().getContent().get(3)).getContent().get(1)).getContent().get(0)).getValue() instanceof Drawing); }
Example #21
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 #22
Source File: ImageReplacementInGlobalParagraphsTest.java From docx-stamper with MIT License | 5 votes |
@Test public void test() throws Docx4JException, IOException { Image monalisa = new Image(getClass().getResourceAsStream("monalisa.jpg")); ImageContext context = new ImageContext(); context.setMonalisa(monalisa); InputStream template = getClass().getResourceAsStream("ImageReplacementInGlobalParagraphsTest.docx"); WordprocessingMLPackage document = stampAndLoad(template, context); Assert.assertTrue(((JAXBElement) ((R) ((P) document.getMainDocumentPart().getContent().get(2)).getContent().get(1)).getContent().get(0)).getValue() instanceof Drawing); Assert.assertTrue(((JAXBElement) ((R) ((P) document.getMainDocumentPart().getContent().get(3)).getContent().get(1)).getContent().get(0)).getValue() instanceof Drawing); }
Example #23
Source File: AddingPageNrToFooter.java From docx4j-template with Apache License 2.0 | 5 votes |
/** * Every fields needs to be delimited by complex field characters. This method * adds the delimiter that precedes the actual field to the given paragraph. * @param paragraph */ private static void addFieldBegin(P paragraph) { R run = factory.createR(); FldChar fldchar = factory.createFldChar(); fldchar.setFldCharType(STFldCharType.BEGIN); run.getContent().add(fldchar); paragraph.getContent().add(run); }
Example #24
Source File: Docx4J_简单例子.java From docx4j-template with Apache License 2.0 | 5 votes |
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_简单例子2.java From docx4j-template with Apache License 2.0 | 5 votes |
public P newImage(WordprocessingMLPackage wordMLPackage, ObjectFactory factory, Part sourcePart, byte[] bytes, String filenameHint, String altText, int id1, int id2, JcEnumeration jcEnumeration) throws Exception { BinaryPartAbstractImage imagePart = BinaryPartAbstractImage .createImagePart(wordMLPackage, sourcePart, bytes); Inline inline = imagePart.createImageInline(filenameHint, altText, id1, id2, false); P p = factory.createP(); R run = factory.createR(); p.getContent().add(run); 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); 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); setParagraphSpacing(factory, p, jcEnumeration, "0", "0"); return p; }
Example #26
Source File: PlaceholderReplacer.java From docx-stamper with MIT License | 5 votes |
public void replace(ParagraphWrapper p, String placeholder, Object replacementObject) { if (replacementObject == null) { replacementObject = RunUtil.create(""); } if (replacementObject instanceof R) { RunUtil.applyParagraphStyle(p.getParagraph(), (R) replacementObject); } p.replace(placeholder, replacementObject); }
Example #27
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 #28
Source File: ParagraphWrapper.java From docx-stamper with MIT License | 5 votes |
public void recalculateRuns() { currentPosition = 0; this.runs.clear(); int index = 0; for (Object contentElement : paragraph.getContent()) { if (contentElement instanceof R && !"".equals(RunUtil.getText((R) contentElement))) { this.addRun((R) contentElement, index); } index++; } }
Example #29
Source File: AddingAnInlineImage.java From docx4j-template with Apache License 2.0 | 5 votes |
/** * 创建一个对象工厂并用它创建一个段落和一个可运行块R. * 然后将可运行块添加到段落中. 接下来创建一个图画并将其添加到可运行块R中. 最后我们将内联 * 对象添加到图画中并返回段落对象. * * @param inline 包含图片的内联对象. * @return 包含图片的段落 */ private static P addInlineImageToParagraph(Inline inline) { // 添加内联对象到一个段落中 ObjectFactory factory = new ObjectFactory(); P paragraph = factory.createP(); R run = factory.createR(); paragraph.getContent().add(run); Drawing drawing = factory.createDrawing(); run.getContent().add(drawing); drawing.getAnchorOrInline().add(inline); return paragraph; }
Example #30
Source File: LineBreakReplacementTest.java From docx-stamper with MIT License | 5 votes |
private void lineBreaksAreReplaced(WordprocessingMLPackage document) { P paragraph = (P) document.getMainDocumentPart().getContent().get(2); Assert.assertTrue(new ParagraphWrapper(paragraph).getText().contains("This paragraph should be")); Assert.assertTrue(new ParagraphWrapper(paragraph).getText().contains("split in")); Assert.assertTrue(new ParagraphWrapper(paragraph).getText().contains("three lines")); Assert.assertEquals(R.class, paragraph.getContent().get(1).getClass()); Assert.assertEquals(Br.class, ((R)paragraph.getContent().get(1)).getContent().get(0).getClass()); Assert.assertEquals(R.class, paragraph.getContent().get(3).getClass()); Assert.assertEquals(Br.class, ((R)paragraph.getContent().get(3)).getContent().get(0).getClass()); }