Search in sources :

Example 1 with R

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);
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) Test(org.junit.Test)

Example 2 with R

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);
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) Text(org.docx4j.wml.Text)

Example 3 with R

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;
}
Also used : P(org.docx4j.wml.P) Drawing(org.docx4j.wml.Drawing) R(org.docx4j.wml.R) ObjectFactory(org.docx4j.wml.ObjectFactory) Inline(org.docx4j.dml.wordprocessingDrawing.Inline) BinaryPartAbstractImage(org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)

Example 4 with R

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;
}
Also used : Drawing(org.docx4j.wml.Drawing) R(org.docx4j.wml.R) PPr(org.docx4j.wml.PPr) STVerticalJc(org.docx4j.wml.STVerticalJc) Jc(org.docx4j.wml.Jc) CTVerticalJc(org.docx4j.wml.CTVerticalJc) Text(org.docx4j.wml.Text) Inline(org.docx4j.dml.wordprocessingDrawing.Inline) BinaryPartAbstractImage(org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)

Example 5 with R

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;
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) PPr(org.docx4j.wml.PPr) PBdr(org.docx4j.wml.PPrBase.PBdr) CTBorder(org.docx4j.wml.CTBorder) Hdr(org.docx4j.wml.Hdr) STVerticalJc(org.docx4j.wml.STVerticalJc) Jc(org.docx4j.wml.Jc) CTVerticalJc(org.docx4j.wml.CTVerticalJc) BigInteger(java.math.BigInteger) Text(org.docx4j.wml.Text)

Aggregations

R (org.docx4j.wml.R)93 P (org.docx4j.wml.P)58 Text (org.docx4j.wml.Text)53 PPr (org.docx4j.wml.PPr)23 Jc (org.docx4j.wml.Jc)18 RPr (org.docx4j.wml.RPr)18 Drawing (org.docx4j.wml.Drawing)17 ObjectFactory (org.docx4j.wml.ObjectFactory)17 CTVerticalJc (org.docx4j.wml.CTVerticalJc)16 STVerticalJc (org.docx4j.wml.STVerticalJc)13 FldChar (org.docx4j.wml.FldChar)11 BigInteger (java.math.BigInteger)10 Inline (org.docx4j.dml.wordprocessingDrawing.Inline)10 BinaryPartAbstractImage (org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)10 Tc (org.docx4j.wml.Tc)10 CTBorder (org.docx4j.wml.CTBorder)8 PBdr (org.docx4j.wml.PPrBase.PBdr)8 Ftr (org.docx4j.wml.Ftr)7 File (java.io.File)6 Tr (org.docx4j.wml.Tr)6