Search in sources :

Example 26 with PPr

use of org.docx4j.wml.PPr in project Java-Tutorial by gpcodervn.

the class NumberingTest method getStyles.

public Styles getStyles() {
    org.docx4j.wml.ObjectFactory wmlObjectFactory = new org.docx4j.wml.ObjectFactory();
    Styles styles = wmlObjectFactory.createStyles();
    // Create object for style
    Style style = wmlObjectFactory.createStyle();
    styles.getStyle().add(style);
    style.setStyleId("MyListStyle");
    // Create object for pPr
    PPr ppr = wmlObjectFactory.createPPr();
    style.setPPr(ppr);
    // Create object for numPr
    PPrBase.NumPr pprbasenumpr = wmlObjectFactory.createPPrBaseNumPr();
    ppr.setNumPr(pprbasenumpr);
    // Create object for numId
    PPrBase.NumPr.NumId pprbasenumprnumid = wmlObjectFactory.createPPrBaseNumPrNumId();
    pprbasenumpr.setNumId(pprbasenumprnumid);
    pprbasenumprnumid.setVal(BigInteger.valueOf(PREDEFINED_OL_NUMID));
    // Create object for uiPriority
    Style.UiPriority styleuipriority = wmlObjectFactory.createStyleUiPriority();
    style.setUiPriority(styleuipriority);
    styleuipriority.setVal(BigInteger.valueOf(99));
    // Create object for name
    Style.Name stylename = wmlObjectFactory.createStyleName();
    style.setName(stylename);
    stylename.setVal("MyListStyle");
    style.setType("numbering");
    // org.docx4j.model.PropertyResolver.init(PropertyResolver.java:173)
    // currently requires a default p style
    styles.getStyle().add(createNormal());
    return styles;
}
Also used : PPr(org.docx4j.wml.PPr) Style(org.docx4j.wml.Style) Styles(org.docx4j.wml.Styles) PPrBase(org.docx4j.wml.PPrBase)

Example 27 with PPr

use of org.docx4j.wml.PPr in project Java-Tutorial by gpcodervn.

the class Docx4jUtils method setHorizontalAlignment.

private void setHorizontalAlignment(P paragraph, JcEnumeration hAlign) {
    if (hAlign != null) {
        PPr pprop = new PPr();
        Jc align = new Jc();
        align.setVal(hAlign);
        pprop.setJc(align);
        paragraph.setPPr(pprop);
    }
}
Also used : PPr(org.docx4j.wml.PPr) Jc(org.docx4j.wml.Jc) STVerticalJc(org.docx4j.wml.STVerticalJc) CTVerticalJc(org.docx4j.wml.CTVerticalJc)

Example 28 with PPr

use of org.docx4j.wml.PPr in project docx4j-template by vindell.

the class Docx4J_例子2 method createHyperlink.

public void createHyperlink(WordprocessingMLPackage wordMLPackage, MainDocumentPart t, ObjectFactory factory, P paragraph, String url, String value, String fontName, String fontSize, JcEnumeration jcEnumeration) throws Exception {
    org.docx4j.relationships.ObjectFactory reFactory = new org.docx4j.relationships.ObjectFactory();
    org.docx4j.relationships.Relationship rel = reFactory.createRelationship();
    rel.setType(Namespaces.HYPERLINK);
    rel.setTarget(url);
    rel.setTargetMode("External");
    t.getRelationshipsPart().addRelationship(rel);
    StringBuffer sb = new StringBuffer();
    // addRelationship sets the rel's @Id
    sb.append("<w:hyperlink r:id=\"");
    sb.append(rel.getId());
    sb.append("\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" ");
    sb.append("xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" >");
    sb.append("<w:r><w:rPr><w:rStyle w:val=\"Hyperlink\" />");
    sb.append("<w:rFonts  w:ascii=\"");
    sb.append(fontName);
    sb.append("\"  w:hAnsi=\"");
    sb.append(fontName);
    sb.append("\"  w:eastAsia=\"");
    sb.append(fontName);
    sb.append("\" w:hint=\"eastAsia\"/>");
    sb.append("<w:sz w:val=\"");
    sb.append(fontSize);
    sb.append("\"/><w:szCs w:val=\"");
    sb.append(fontSize);
    sb.append("\"/></w:rPr><w:t>");
    sb.append(value);
    sb.append("</w:t></w:r></w:hyperlink>");
    Hyperlink link = (Hyperlink) XmlUtils.unmarshalString(sb.toString());
    paragraph.getContent().add(link);
    setParagraphSpacing(factory, paragraph, jcEnumeration, true, "0", "0", null, null, true, "240", STLineSpacingRule.AUTO);
    PPr ppr = paragraph.getPPr();
    if (ppr == null) {
        ppr = factory.createPPr();
    }
    RFonts fonts = new RFonts();
    fonts.setAscii("微软雅黑");
    fonts.setHAnsi("微软雅黑");
    fonts.setEastAsia("微软雅黑");
    fonts.setHint(STHint.EAST_ASIA);
    ParaRPr rpr = new ParaRPr();
    rpr.setRFonts(fonts);
    ppr.setRPr(rpr);
    paragraph.setPPr(ppr);
}
Also used : PPr(org.docx4j.wml.PPr) ObjectFactory(org.docx4j.wml.ObjectFactory) Relationship(org.docx4j.relationships.Relationship) ParaRPr(org.docx4j.wml.ParaRPr) RFonts(org.docx4j.wml.RFonts) Hyperlink(org.docx4j.wml.P.Hyperlink)

Example 29 with PPr

use of org.docx4j.wml.PPr in project docx4j-template by vindell.

the class Docx4J_例子2 method setParagraphSpacing.

// 设置段间距-->行距 段前段后距离
// 段前段后可以设置行和磅 行距只有磅
// 段前磅值和行值同时设置,只有行值起作用
// TODO 1磅=20 1行=100 单倍行距=240 为什么是这个值不知道
/**
 * @param jcEnumeration
 *            对齐方式
 * @param isSpace
 *            是否设置段前段后值
 * @param before
 *            段前磅数
 * @param after
 *            段后磅数
 * @param beforeLines
 *            段前行数
 * @param afterLines
 *            段后行数
 * @param isLine
 *            是否设置行距
 * @param lineValue
 *            行距值
 * @param sTLineSpacingRule
 *            自动auto 固定exact 最小 atLeast
 */
public void setParagraphSpacing(ObjectFactory factory, P p, JcEnumeration jcEnumeration, boolean isSpace, String before, String after, String beforeLines, String afterLines, boolean isLine, String lineValue, STLineSpacingRule sTLineSpacingRule) {
    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);
    Spacing spacing = new Spacing();
    if (isSpace) {
        if (before != null) {
            // 段前磅数
            spacing.setBefore(new BigInteger(before));
        }
        if (after != null) {
            // 段后磅数
            spacing.setAfter(new BigInteger(after));
        }
        if (beforeLines != null) {
            // 段前行数
            spacing.setBeforeLines(new BigInteger(beforeLines));
        }
        if (afterLines != null) {
            // 段后行数
            spacing.setAfterLines(new BigInteger(afterLines));
        }
    }
    if (isLine) {
        if (lineValue != null) {
            spacing.setLine(new BigInteger(lineValue));
        }
        spacing.setLineRule(sTLineSpacingRule);
    }
    pPr.setSpacing(spacing);
    p.setPPr(pPr);
}
Also used : PPr(org.docx4j.wml.PPr) STVerticalJc(org.docx4j.wml.STVerticalJc) Jc(org.docx4j.wml.Jc) CTVerticalJc(org.docx4j.wml.CTVerticalJc) BigInteger(java.math.BigInteger) Spacing(org.docx4j.wml.PPrBase.Spacing)

Example 30 with PPr

use of org.docx4j.wml.PPr in project docx4j-template by vindell.

the class Docx4J_例子2 method newImage.

public P newImage(WordprocessingMLPackage wordMLPackage, ObjectFactory factory, Part sourcePart, byte[] bytes, String filenameHint, String altText, int id1, int id2, boolean isUnderLine, String underLineSize, 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);
    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(underLineSize));
        pBdr.setBetween(value);
        pPr.setPBdr(pBdr);
    }
    setParagraphSpacing(factory, p, jcEnumeration, true, "0", "0", null, null, true, "240", STLineSpacingRule.AUTO);
    return p;
}
Also used : P(org.docx4j.wml.P) Drawing(org.docx4j.wml.Drawing) R(org.docx4j.wml.R) PPr(org.docx4j.wml.PPr) PBdr(org.docx4j.wml.PPrBase.PBdr) CTBorder(org.docx4j.wml.CTBorder) STVerticalJc(org.docx4j.wml.STVerticalJc) Jc(org.docx4j.wml.Jc) CTVerticalJc(org.docx4j.wml.CTVerticalJc) BigInteger(java.math.BigInteger) Inline(org.docx4j.dml.wordprocessingDrawing.Inline) BinaryPartAbstractImage(org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)

Aggregations

PPr (org.docx4j.wml.PPr)48 Jc (org.docx4j.wml.Jc)29 R (org.docx4j.wml.R)23 P (org.docx4j.wml.P)22 CTVerticalJc (org.docx4j.wml.CTVerticalJc)21 STVerticalJc (org.docx4j.wml.STVerticalJc)20 BigInteger (java.math.BigInteger)17 Text (org.docx4j.wml.Text)14 PBdr (org.docx4j.wml.PPrBase.PBdr)10 CTBorder (org.docx4j.wml.CTBorder)9 RPr (org.docx4j.wml.RPr)6 Inline (org.docx4j.dml.wordprocessingDrawing.Inline)5 BinaryPartAbstractImage (org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)5 Drawing (org.docx4j.wml.Drawing)5 Spacing (org.docx4j.wml.PPrBase.Spacing)5 Ftr (org.docx4j.wml.Ftr)4 ObjectFactory (org.docx4j.wml.ObjectFactory)4 ParaRPr (org.docx4j.wml.ParaRPr)4 Ind (org.docx4j.wml.PPrBase.Ind)3 Tc (org.docx4j.wml.Tc)3