use of org.docx4j.wml.R in project Java-Tutorial by gpcodervn.
the class HyperlinkTest method testNamedAnchorInSpan.
@Test
public void testNamedAnchorInSpan() throws Docx4JException {
String name = "anchor3";
String href = null;
String content = "Google";
List<Object> objects = fromXHTML("<span>" + a(href, name, content) + "</span>");
P p = (P) objects.get(0);
// Test bookmark
testBookmarkName(XmlUtils.unwrap(p.getContent().get(0)), name);
// Test content - not hyperlinked
R r = (R) p.getContent().get(1);
testContent(r, R.class, content);
}
use of org.docx4j.wml.R in project Java-Tutorial by gpcodervn.
the class HyperlinkTest method testContent.
private void testContent(Object o, Class clazz, String content) {
assertEquals(o.getClass(), clazz);
Object o2;
if (o instanceof P.Hyperlink) {
P.Hyperlink h = (P.Hyperlink) o;
o2 = XmlUtils.unwrap(((R) h.getContent().get(0)).getContent().get(0));
} else {
R r = (R) o;
o2 = XmlUtils.unwrap(r.getContent().get(0));
}
String runText = ((Text) o2).getValue();
assertEquals(content, runText);
}
use of org.docx4j.wml.R in project Java-Tutorial by gpcodervn.
the class Docx4jUtils method newImage.
public P newImage(WordprocessingMLPackage wordMLPackage, 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
ObjectFactory factory = Context.getWmlObjectFactory();
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;
}
use of org.docx4j.wml.R in project docx4j-template by vindell.
the class Docx4J_例子2 method createImageParagraph.
// 段落中插入文字和图片
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, true, "0", "0", null, null, true, "240", STLineSpacingRule.AUTO);
return p;
}
use of org.docx4j.wml.R in project docx4j-template by vindell.
the class Docx4J_例子2 method getTextHdr.
public Hdr getTextHdr(WordprocessingMLPackage wordprocessingMLPackage, ObjectFactory factory, Part sourcePart, String content, boolean isUnderLine, String underLineSz, 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);
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);
headP.setPPr(pPr);
}
setParagraphSpacing(factory, headP, jcEnumeration, true, "0", "0", null, null, true, "240", STLineSpacingRule.AUTO);
hdr.getContent().add(headP);
if (isUnderLine) {
hdr.getContent().add(createHeaderBlankP(wordprocessingMLPackage, factory, underLineSz, jcEnumeration));
}
return hdr;
}
Aggregations