Search in sources :

Example 16 with BooleanDefaultTrue

use of org.docx4j.wml.BooleanDefaultTrue in project tutorials by eugenp.

the class Docx4jExample method createDocumentPackage.

void createDocumentPackage(String outputPath, String imagePath) throws Exception {
    WordprocessingMLPackage wordPackage = WordprocessingMLPackage.createPackage();
    MainDocumentPart mainDocumentPart = wordPackage.getMainDocumentPart();
    mainDocumentPart.addStyledParagraphOfText("Title", "Hello World!");
    mainDocumentPart.addParagraphOfText("Welcome To Baeldung!");
    ObjectFactory factory = Context.getWmlObjectFactory();
    P p = factory.createP();
    R r = factory.createR();
    Text t = factory.createText();
    t.setValue("Welcome To Baeldung");
    r.getContent().add(t);
    p.getContent().add(r);
    RPr rpr = factory.createRPr();
    BooleanDefaultTrue b = new BooleanDefaultTrue();
    rpr.setB(b);
    rpr.setI(b);
    rpr.setCaps(b);
    Color red = factory.createColor();
    red.setVal("green");
    rpr.setColor(red);
    r.setRPr(rpr);
    mainDocumentPart.getContent().add(p);
    File image = new File(imagePath);
    byte[] fileContent = Files.readAllBytes(image.toPath());
    BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordPackage, fileContent);
    Inline inline = imagePart.createImageInline("Baeldung Image", "Alt Text", 1, 2, false);
    P Imageparagraph = addImageToParagraph(inline);
    mainDocumentPart.getContent().add(Imageparagraph);
    int writableWidthTwips = wordPackage.getDocumentModel().getSections().get(0).getPageDimensions().getWritableWidthTwips();
    int columnNumber = 3;
    Tbl tbl = TblFactory.createTable(3, 3, writableWidthTwips / columnNumber);
    List<Object> rows = tbl.getContent();
    for (Object row : rows) {
        Tr tr = (Tr) row;
        List<Object> cells = tr.getContent();
        for (Object cell : cells) {
            Tc td = (Tc) cell;
            td.getContent().add(p);
        }
    }
    mainDocumentPart.getContent().add(tbl);
    File exportFile = new File(outputPath);
    wordPackage.save(exportFile);
}
Also used : MainDocumentPart(org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart) Color(org.docx4j.wml.Color) Text(org.docx4j.wml.Text) BooleanDefaultTrue(org.docx4j.wml.BooleanDefaultTrue) Inline(org.docx4j.dml.wordprocessingDrawing.Inline) WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) Tc(org.docx4j.wml.Tc) P(org.docx4j.wml.P) R(org.docx4j.wml.R) ObjectFactory(org.docx4j.wml.ObjectFactory) RPr(org.docx4j.wml.RPr) BinaryPartAbstractImage(org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage) File(java.io.File) Tr(org.docx4j.wml.Tr) Tbl(org.docx4j.wml.Tbl)

Example 17 with BooleanDefaultTrue

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

the class Docx4J_简单例子 method getRPr.

/**
 * 创建字体
 *
 * @param isBlod
 *            粗体
 * @param isUnderLine
 *            下划线
 * @param isItalic
 *            斜体
 * @param isStrike
 *            删除线
 */
public RPr getRPr(ObjectFactory factory, String fontFamily, String colorVal, String fontSize, STHint sTHint, boolean isBlod, boolean isUnderLine, boolean isItalic, boolean isStrike) {
    RPr rPr = factory.createRPr();
    RFonts rf = new RFonts();
    rf.setHint(sTHint);
    rf.setAscii(fontFamily);
    rf.setHAnsi(fontFamily);
    rPr.setRFonts(rf);
    BooleanDefaultTrue bdt = factory.createBooleanDefaultTrue();
    rPr.setBCs(bdt);
    if (isBlod) {
        rPr.setB(bdt);
    }
    if (isItalic) {
        rPr.setI(bdt);
    }
    if (isStrike) {
        rPr.setStrike(bdt);
    }
    if (isUnderLine) {
        U underline = new U();
        underline.setVal(UnderlineEnumeration.SINGLE);
        rPr.setU(underline);
    }
    Color color = new Color();
    color.setVal(colorVal);
    rPr.setColor(color);
    HpsMeasure sz = new HpsMeasure();
    sz.setVal(new BigInteger(fontSize));
    rPr.setSz(sz);
    rPr.setSzCs(sz);
    return rPr;
}
Also used : RPr(org.docx4j.wml.RPr) U(org.docx4j.wml.U) HpsMeasure(org.docx4j.wml.HpsMeasure) Color(org.docx4j.wml.Color) RFonts(org.docx4j.wml.RFonts) BigInteger(java.math.BigInteger) BooleanDefaultTrue(org.docx4j.wml.BooleanDefaultTrue)

Example 18 with BooleanDefaultTrue

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

the class Docx4J_简单例子2 method getRPr.

/**
 * 创建字体
 *
 * @param isBlod
 *            粗体
 * @param isUnderLine
 *            下划线
 * @param isItalic
 *            斜体
 * @param isStrike
 *            删除线
 */
public RPr getRPr(ObjectFactory factory, String fontFamily, String colorVal, String fontSize, STHint sTHint, boolean isBlod, boolean isUnderLine, boolean isItalic, boolean isStrike) {
    RPr rPr = factory.createRPr();
    RFonts rf = new RFonts();
    rf.setHint(sTHint);
    rf.setAscii(fontFamily);
    rf.setHAnsi(fontFamily);
    rPr.setRFonts(rf);
    BooleanDefaultTrue bdt = factory.createBooleanDefaultTrue();
    rPr.setBCs(bdt);
    if (isBlod) {
        rPr.setB(bdt);
    }
    if (isItalic) {
        rPr.setI(bdt);
    }
    if (isStrike) {
        rPr.setStrike(bdt);
    }
    if (isUnderLine) {
        U underline = new U();
        underline.setVal(UnderlineEnumeration.SINGLE);
        rPr.setU(underline);
    }
    Color color = new Color();
    color.setVal(colorVal);
    rPr.setColor(color);
    HpsMeasure sz = new HpsMeasure();
    sz.setVal(new BigInteger(fontSize));
    rPr.setSz(sz);
    rPr.setSzCs(sz);
    return rPr;
}
Also used : RPr(org.docx4j.wml.RPr) U(org.docx4j.wml.U) HpsMeasure(org.docx4j.wml.HpsMeasure) Color(org.docx4j.wml.Color) RFonts(org.docx4j.wml.RFonts) BigInteger(java.math.BigInteger) BooleanDefaultTrue(org.docx4j.wml.BooleanDefaultTrue)

Example 19 with BooleanDefaultTrue

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

the class Docx4jStyle_S3 method addItalicStyle.

public void addItalicStyle(RPr runProperties) {
    BooleanDefaultTrue b = new BooleanDefaultTrue();
    b.setVal(true);
    runProperties.setI(b);
}
Also used : BooleanDefaultTrue(org.docx4j.wml.BooleanDefaultTrue)

Example 20 with BooleanDefaultTrue

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

the class Docx4j_工具类_S3_Test method addRPrOutlineStyle.

/**
 * @Description: 空心
 */
public void addRPrOutlineStyle(RPr runProperties) {
    BooleanDefaultTrue outline = new BooleanDefaultTrue();
    outline.setVal(true);
    runProperties.setOutline(outline);
}
Also used : BooleanDefaultTrue(org.docx4j.wml.BooleanDefaultTrue)

Aggregations

BooleanDefaultTrue (org.docx4j.wml.BooleanDefaultTrue)28 RPr (org.docx4j.wml.RPr)9 Color (org.docx4j.wml.Color)6 HpsMeasure (org.docx4j.wml.HpsMeasure)5 ObjectFactory (org.docx4j.wml.ObjectFactory)5 P (org.docx4j.wml.P)5 R (org.docx4j.wml.R)5 BigInteger (java.math.BigInteger)4 RFonts (org.docx4j.wml.RFonts)4 U (org.docx4j.wml.U)4 File (java.io.File)2 WordprocessingMLPackage (org.docx4j.openpackaging.packages.WordprocessingMLPackage)2 MainDocumentPart (org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart)2 ParaRPr (org.docx4j.wml.ParaRPr)2 TcPr (org.docx4j.wml.TcPr)2 Text (org.docx4j.wml.Text)2 Inline (org.docx4j.dml.wordprocessingDrawing.Inline)1 BinaryPartAbstractImage (org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)1 CTShd (org.docx4j.wml.CTShd)1 Highlight (org.docx4j.wml.Highlight)1