Search in sources :

Example 1 with Numbering

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

the class NumberingTest method getNumbering.

public Numbering getNumbering() {
    org.docx4j.wml.ObjectFactory wmlObjectFactory = new org.docx4j.wml.ObjectFactory();
    Numbering numbering = wmlObjectFactory.createNumbering();
    // Create object for numberingnum
    Numbering.Num numberingnum = wmlObjectFactory.createNumberingNum();
    numbering.getNum().add(numberingnum);
    // so we can detect this in use
    numberingnum.setNumId(BigInteger.valueOf(PREDEFINED_OL_NUMID));
    // Create object for abstractNumId
    Numbering.Num.AbstractNumId numberingnumabstractnumid = wmlObjectFactory.createNumberingNumAbstractNumId();
    numberingnum.setAbstractNumId(numberingnumabstractnumid);
    numberingnumabstractnumid.setVal(BigInteger.valueOf(PREDEFINED_OL_ABSTRACT_NUMID));
    // Create object for abstractNum
    Numbering.AbstractNum numberingabstractnum = wmlObjectFactory.createNumberingAbstractNum();
    numbering.getAbstractNum().add(numberingabstractnum);
    numberingabstractnum.setAbstractNumId(BigInteger.valueOf(PREDEFINED_OL_ABSTRACT_NUMID));
    // Create object for lvl
    Lvl lvl = wmlObjectFactory.createLvl();
    numberingabstractnum.getLvl().add(lvl);
    lvl.setIlvl(BigInteger.valueOf(0));
    // Create object for pPr
    PPr ppr = wmlObjectFactory.createPPr();
    lvl.setPPr(ppr);
    // Create object for ind
    PPrBase.Ind pprbaseind = wmlObjectFactory.createPPrBaseInd();
    ppr.setInd(pprbaseind);
    pprbaseind.setLeft(BigInteger.valueOf(720));
    pprbaseind.setHanging(BigInteger.valueOf(360));
    // Create object for rPr
    RPr rpr = wmlObjectFactory.createRPr();
    lvl.setRPr(rpr);
    // Create object for rFonts
    RFonts rfonts = wmlObjectFactory.createRFonts();
    rpr.setRFonts(rfonts);
    rfonts.setAscii("Symbol");
    rfonts.setHint(org.docx4j.wml.STHint.DEFAULT);
    rfonts.setHAnsi("Symbol");
    // Create object for numFmt
    NumFmt numfmt = wmlObjectFactory.createNumFmt();
    lvl.setNumFmt(numfmt);
    numfmt.setVal(org.docx4j.wml.NumberFormat.BULLET);
    // Create object for lvlText
    Lvl.LvlText lvllvltext = wmlObjectFactory.createLvlLvlText();
    lvl.setLvlText(lvllvltext);
    lvllvltext.setVal("");
    // Create object for lvlJc
    Jc jc = wmlObjectFactory.createJc();
    lvl.setLvlJc(jc);
    jc.setVal(org.docx4j.wml.JcEnumeration.LEFT);
    // Create object for start
    Lvl.Start lvlstart = wmlObjectFactory.createLvlStart();
    lvl.setStart(lvlstart);
    lvlstart.setVal(BigInteger.valueOf(1));
    // Create object for lvl
    Lvl lvl2 = wmlObjectFactory.createLvl();
    numberingabstractnum.getLvl().add(lvl2);
    lvl2.setIlvl(BigInteger.valueOf(1));
    // Create object for pPr
    PPr ppr2 = wmlObjectFactory.createPPr();
    lvl2.setPPr(ppr2);
    // Create object for ind
    PPrBase.Ind pprbaseind2 = wmlObjectFactory.createPPrBaseInd();
    ppr2.setInd(pprbaseind2);
    pprbaseind2.setLeft(BigInteger.valueOf(1440));
    pprbaseind2.setHanging(BigInteger.valueOf(360));
    // Create object for rPr
    RPr rpr2 = wmlObjectFactory.createRPr();
    lvl2.setRPr(rpr2);
    // Create object for rFonts
    RFonts rfonts2 = wmlObjectFactory.createRFonts();
    rpr2.setRFonts(rfonts2);
    rfonts2.setAscii("Courier New");
    rfonts2.setHint(org.docx4j.wml.STHint.DEFAULT);
    rfonts2.setHAnsi("Courier New");
    rfonts2.setCs("Courier New");
    // Create object for numFmt
    NumFmt numfmt2 = wmlObjectFactory.createNumFmt();
    lvl2.setNumFmt(numfmt2);
    numfmt2.setVal(org.docx4j.wml.NumberFormat.BULLET);
    // Create object for lvlText
    Lvl.LvlText lvllvltext2 = wmlObjectFactory.createLvlLvlText();
    lvl2.setLvlText(lvllvltext2);
    lvllvltext2.setVal("o");
    // Create object for lvlJc
    Jc jc2 = wmlObjectFactory.createJc();
    lvl2.setLvlJc(jc2);
    jc2.setVal(org.docx4j.wml.JcEnumeration.LEFT);
    // Create object for start
    Lvl.Start lvlstart2 = wmlObjectFactory.createLvlStart();
    lvl2.setStart(lvlstart2);
    lvlstart2.setVal(BigInteger.valueOf(1));
    // Create object for lvl
    Lvl lvl3 = wmlObjectFactory.createLvl();
    numberingabstractnum.getLvl().add(lvl3);
    lvl3.setIlvl(BigInteger.valueOf(2));
    // Create object for pPr
    PPr ppr3 = wmlObjectFactory.createPPr();
    lvl3.setPPr(ppr3);
    // Create object for ind
    PPrBase.Ind pprbaseind3 = wmlObjectFactory.createPPrBaseInd();
    ppr3.setInd(pprbaseind3);
    pprbaseind3.setLeft(BigInteger.valueOf(2160));
    pprbaseind3.setHanging(BigInteger.valueOf(360));
    // Create object for rPr
    RPr rpr3 = wmlObjectFactory.createRPr();
    lvl3.setRPr(rpr3);
    // Create object for rFonts
    RFonts rfonts3 = wmlObjectFactory.createRFonts();
    rpr3.setRFonts(rfonts3);
    rfonts3.setAscii("Wingdings");
    rfonts3.setHint(org.docx4j.wml.STHint.DEFAULT);
    rfonts3.setHAnsi("Wingdings");
    // Create object for numFmt
    NumFmt numfmt3 = wmlObjectFactory.createNumFmt();
    lvl3.setNumFmt(numfmt3);
    numfmt3.setVal(org.docx4j.wml.NumberFormat.BULLET);
    // Create object for lvlText
    Lvl.LvlText lvllvltext3 = wmlObjectFactory.createLvlLvlText();
    lvl3.setLvlText(lvllvltext3);
    lvllvltext3.setVal("");
    // Create object for lvlJc
    Jc jc3 = wmlObjectFactory.createJc();
    lvl3.setLvlJc(jc3);
    jc3.setVal(org.docx4j.wml.JcEnumeration.LEFT);
    // Create object for start
    Lvl.Start lvlstart3 = wmlObjectFactory.createLvlStart();
    lvl3.setStart(lvlstart3);
    lvlstart3.setVal(BigInteger.valueOf(1));
    // Create object for lvl
    Lvl lvl4 = wmlObjectFactory.createLvl();
    numberingabstractnum.getLvl().add(lvl4);
    lvl4.setIlvl(BigInteger.valueOf(3));
    // Create object for pPr
    PPr ppr4 = wmlObjectFactory.createPPr();
    lvl4.setPPr(ppr4);
    // Create object for ind
    PPrBase.Ind pprbaseind4 = wmlObjectFactory.createPPrBaseInd();
    ppr4.setInd(pprbaseind4);
    pprbaseind4.setLeft(BigInteger.valueOf(2880));
    pprbaseind4.setHanging(BigInteger.valueOf(360));
    // Create object for rPr
    RPr rpr4 = wmlObjectFactory.createRPr();
    lvl4.setRPr(rpr4);
    // Create object for rFonts
    RFonts rfonts4 = wmlObjectFactory.createRFonts();
    rpr4.setRFonts(rfonts4);
    rfonts4.setAscii("Symbol");
    rfonts4.setHint(org.docx4j.wml.STHint.DEFAULT);
    rfonts4.setHAnsi("Symbol");
    // Create object for numFmt
    NumFmt numfmt4 = wmlObjectFactory.createNumFmt();
    lvl4.setNumFmt(numfmt4);
    numfmt4.setVal(org.docx4j.wml.NumberFormat.BULLET);
    // Create object for lvlText
    Lvl.LvlText lvllvltext4 = wmlObjectFactory.createLvlLvlText();
    lvl4.setLvlText(lvllvltext4);
    lvllvltext4.setVal("");
    // Create object for lvlJc
    Jc jc4 = wmlObjectFactory.createJc();
    lvl4.setLvlJc(jc4);
    jc4.setVal(org.docx4j.wml.JcEnumeration.LEFT);
    // Create object for start
    Lvl.Start lvlstart4 = wmlObjectFactory.createLvlStart();
    lvl4.setStart(lvlstart4);
    lvlstart4.setVal(BigInteger.valueOf(1));
    // Create object for lvl
    Lvl lvl5 = wmlObjectFactory.createLvl();
    numberingabstractnum.getLvl().add(lvl5);
    lvl5.setIlvl(BigInteger.valueOf(4));
    // Create object for pPr
    PPr ppr5 = wmlObjectFactory.createPPr();
    lvl5.setPPr(ppr5);
    // Create object for ind
    PPrBase.Ind pprbaseind5 = wmlObjectFactory.createPPrBaseInd();
    ppr5.setInd(pprbaseind5);
    pprbaseind5.setLeft(BigInteger.valueOf(3600));
    pprbaseind5.setHanging(BigInteger.valueOf(360));
    // Create object for rPr
    RPr rpr5 = wmlObjectFactory.createRPr();
    lvl5.setRPr(rpr5);
    // Create object for rFonts
    RFonts rfonts5 = wmlObjectFactory.createRFonts();
    rpr5.setRFonts(rfonts5);
    rfonts5.setAscii("Courier New");
    rfonts5.setHint(org.docx4j.wml.STHint.DEFAULT);
    rfonts5.setHAnsi("Courier New");
    rfonts5.setCs("Courier New");
    // Create object for numFmt
    NumFmt numfmt5 = wmlObjectFactory.createNumFmt();
    lvl5.setNumFmt(numfmt5);
    numfmt5.setVal(org.docx4j.wml.NumberFormat.BULLET);
    // Create object for lvlText
    Lvl.LvlText lvllvltext5 = wmlObjectFactory.createLvlLvlText();
    lvl5.setLvlText(lvllvltext5);
    lvllvltext5.setVal("o");
    // Create object for lvlJc
    Jc jc5 = wmlObjectFactory.createJc();
    lvl5.setLvlJc(jc5);
    jc5.setVal(org.docx4j.wml.JcEnumeration.LEFT);
    // Create object for start
    Lvl.Start lvlstart5 = wmlObjectFactory.createLvlStart();
    lvl5.setStart(lvlstart5);
    lvlstart5.setVal(BigInteger.valueOf(1));
    // Create object for lvl
    Lvl lvl6 = wmlObjectFactory.createLvl();
    numberingabstractnum.getLvl().add(lvl6);
    lvl6.setIlvl(BigInteger.valueOf(5));
    // Create object for pPr
    PPr ppr6 = wmlObjectFactory.createPPr();
    lvl6.setPPr(ppr6);
    // Create object for ind
    PPrBase.Ind pprbaseind6 = wmlObjectFactory.createPPrBaseInd();
    ppr6.setInd(pprbaseind6);
    pprbaseind6.setLeft(BigInteger.valueOf(4320));
    pprbaseind6.setHanging(BigInteger.valueOf(360));
    // Create object for rPr
    RPr rpr6 = wmlObjectFactory.createRPr();
    lvl6.setRPr(rpr6);
    // Create object for rFonts
    RFonts rfonts6 = wmlObjectFactory.createRFonts();
    rpr6.setRFonts(rfonts6);
    rfonts6.setAscii("Wingdings");
    rfonts6.setHint(org.docx4j.wml.STHint.DEFAULT);
    rfonts6.setHAnsi("Wingdings");
    // Create object for numFmt
    NumFmt numfmt6 = wmlObjectFactory.createNumFmt();
    lvl6.setNumFmt(numfmt6);
    numfmt6.setVal(org.docx4j.wml.NumberFormat.BULLET);
    // Create object for lvlText
    Lvl.LvlText lvllvltext6 = wmlObjectFactory.createLvlLvlText();
    lvl6.setLvlText(lvllvltext6);
    lvllvltext6.setVal("");
    // Create object for lvlJc
    Jc jc6 = wmlObjectFactory.createJc();
    lvl6.setLvlJc(jc6);
    jc6.setVal(org.docx4j.wml.JcEnumeration.LEFT);
    // Create object for start
    Lvl.Start lvlstart6 = wmlObjectFactory.createLvlStart();
    lvl6.setStart(lvlstart6);
    lvlstart6.setVal(BigInteger.valueOf(1));
    // Create object for lvl
    Lvl lvl7 = wmlObjectFactory.createLvl();
    numberingabstractnum.getLvl().add(lvl7);
    lvl7.setIlvl(BigInteger.valueOf(6));
    // Create object for pPr
    PPr ppr7 = wmlObjectFactory.createPPr();
    lvl7.setPPr(ppr7);
    // Create object for ind
    PPrBase.Ind pprbaseind7 = wmlObjectFactory.createPPrBaseInd();
    ppr7.setInd(pprbaseind7);
    pprbaseind7.setLeft(BigInteger.valueOf(5040));
    pprbaseind7.setHanging(BigInteger.valueOf(360));
    // Create object for rPr
    RPr rpr7 = wmlObjectFactory.createRPr();
    lvl7.setRPr(rpr7);
    // Create object for rFonts
    RFonts rfonts7 = wmlObjectFactory.createRFonts();
    rpr7.setRFonts(rfonts7);
    rfonts7.setAscii("Symbol");
    rfonts7.setHint(org.docx4j.wml.STHint.DEFAULT);
    rfonts7.setHAnsi("Symbol");
    // Create object for numFmt
    NumFmt numfmt7 = wmlObjectFactory.createNumFmt();
    lvl7.setNumFmt(numfmt7);
    numfmt7.setVal(org.docx4j.wml.NumberFormat.BULLET);
    // Create object for lvlText
    Lvl.LvlText lvllvltext7 = wmlObjectFactory.createLvlLvlText();
    lvl7.setLvlText(lvllvltext7);
    lvllvltext7.setVal("");
    // Create object for lvlJc
    Jc jc7 = wmlObjectFactory.createJc();
    lvl7.setLvlJc(jc7);
    jc7.setVal(org.docx4j.wml.JcEnumeration.LEFT);
    // Create object for start
    Lvl.Start lvlstart7 = wmlObjectFactory.createLvlStart();
    lvl7.setStart(lvlstart7);
    lvlstart7.setVal(BigInteger.valueOf(1));
    // Create object for lvl
    Lvl lvl8 = wmlObjectFactory.createLvl();
    numberingabstractnum.getLvl().add(lvl8);
    lvl8.setIlvl(BigInteger.valueOf(7));
    // Create object for pPr
    PPr ppr8 = wmlObjectFactory.createPPr();
    lvl8.setPPr(ppr8);
    // Create object for ind
    PPrBase.Ind pprbaseind8 = wmlObjectFactory.createPPrBaseInd();
    ppr8.setInd(pprbaseind8);
    pprbaseind8.setLeft(BigInteger.valueOf(5760));
    pprbaseind8.setHanging(BigInteger.valueOf(360));
    // Create object for rPr
    RPr rpr8 = wmlObjectFactory.createRPr();
    lvl8.setRPr(rpr8);
    // Create object for rFonts
    RFonts rfonts8 = wmlObjectFactory.createRFonts();
    rpr8.setRFonts(rfonts8);
    rfonts8.setAscii("Courier New");
    rfonts8.setHint(org.docx4j.wml.STHint.DEFAULT);
    rfonts8.setHAnsi("Courier New");
    rfonts8.setCs("Courier New");
    // Create object for numFmt
    NumFmt numfmt8 = wmlObjectFactory.createNumFmt();
    lvl8.setNumFmt(numfmt8);
    numfmt8.setVal(org.docx4j.wml.NumberFormat.BULLET);
    // Create object for lvlText
    Lvl.LvlText lvllvltext8 = wmlObjectFactory.createLvlLvlText();
    lvl8.setLvlText(lvllvltext8);
    lvllvltext8.setVal("o");
    // Create object for lvlJc
    Jc jc8 = wmlObjectFactory.createJc();
    lvl8.setLvlJc(jc8);
    jc8.setVal(org.docx4j.wml.JcEnumeration.LEFT);
    // Create object for start
    Lvl.Start lvlstart8 = wmlObjectFactory.createLvlStart();
    lvl8.setStart(lvlstart8);
    lvlstart8.setVal(BigInteger.valueOf(1));
    // Create object for lvl
    Lvl lvl9 = wmlObjectFactory.createLvl();
    numberingabstractnum.getLvl().add(lvl9);
    lvl9.setIlvl(BigInteger.valueOf(8));
    // Create object for pPr
    PPr ppr9 = wmlObjectFactory.createPPr();
    lvl9.setPPr(ppr9);
    // Create object for ind
    PPrBase.Ind pprbaseind9 = wmlObjectFactory.createPPrBaseInd();
    ppr9.setInd(pprbaseind9);
    pprbaseind9.setLeft(BigInteger.valueOf(6480));
    pprbaseind9.setHanging(BigInteger.valueOf(360));
    // Create object for rPr
    RPr rpr9 = wmlObjectFactory.createRPr();
    lvl9.setRPr(rpr9);
    // Create object for rFonts
    RFonts rfonts9 = wmlObjectFactory.createRFonts();
    rpr9.setRFonts(rfonts9);
    rfonts9.setAscii("Wingdings");
    rfonts9.setHint(org.docx4j.wml.STHint.DEFAULT);
    rfonts9.setHAnsi("Wingdings");
    // Create object for numFmt
    NumFmt numfmt9 = wmlObjectFactory.createNumFmt();
    lvl9.setNumFmt(numfmt9);
    numfmt9.setVal(org.docx4j.wml.NumberFormat.BULLET);
    // Create object for lvlText
    Lvl.LvlText lvllvltext9 = wmlObjectFactory.createLvlLvlText();
    lvl9.setLvlText(lvllvltext9);
    lvllvltext9.setVal("");
    // Create object for lvlJc
    Jc jc9 = wmlObjectFactory.createJc();
    lvl9.setLvlJc(jc9);
    jc9.setVal(org.docx4j.wml.JcEnumeration.LEFT);
    // Create object for start
    Lvl.Start lvlstart9 = wmlObjectFactory.createLvlStart();
    lvl9.setStart(lvlstart9);
    lvlstart9.setVal(BigInteger.valueOf(1));
    // Create object for nsid
    CTLongHexNumber longhexnumber = wmlObjectFactory.createCTLongHexNumber();
    numberingabstractnum.setNsid(longhexnumber);
    longhexnumber.setVal("2C877BED");
    // Create object for multiLevelType
    Numbering.AbstractNum.MultiLevelType numberingabstractnummultileveltype = wmlObjectFactory.createNumberingAbstractNumMultiLevelType();
    numberingabstractnum.setMultiLevelType(numberingabstractnummultileveltype);
    numberingabstractnummultileveltype.setVal("multilevel");
    // Create object for tmpl
    CTLongHexNumber longhexnumber2 = wmlObjectFactory.createCTLongHexNumber();
    numberingabstractnum.setTmpl(longhexnumber2);
    longhexnumber2.setVal("04905A0A");
    // Create object for styleLink
    Numbering.AbstractNum.StyleLink numberingabstractnumstylelink = wmlObjectFactory.createNumberingAbstractNumStyleLink();
    numberingabstractnum.setStyleLink(numberingabstractnumstylelink);
    numberingabstractnumstylelink.setVal("MyListStyle");
    return numbering;
}
Also used : Lvl(org.docx4j.wml.Lvl) Ind(org.docx4j.wml.PPrBase.Ind) CTLongHexNumber(org.docx4j.wml.CTLongHexNumber) RFonts(org.docx4j.wml.RFonts) Numbering(org.docx4j.wml.Numbering) PPr(org.docx4j.wml.PPr) RPr(org.docx4j.wml.RPr) Jc(org.docx4j.wml.Jc) NumFmt(org.docx4j.wml.NumFmt) PPrBase(org.docx4j.wml.PPrBase)

Example 2 with Numbering

use of org.docx4j.wml.Numbering in project flexmark-java by vsch.

the class DocxRenderer method setDefaultStyleAndNumbering.

static void setDefaultStyleAndNumbering(WordprocessingMLPackage out, final DataHolder options) {
    try {
        // (main doc part it if necessary)
        MainDocumentPart documentPart = out.getMainDocumentPart();
        if (documentPart == null) {
            try {
                documentPart = new MainDocumentPart();
                out.addTargetPart(documentPart);
            } catch (InvalidFormatException e) {
                e.printStackTrace();
            }
        }
        if (documentPart.getStyleDefinitionsPart() == null) {
            Part stylesPart = new org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart();
            final Styles styles = (Styles) XmlUtils.unmarshalString(STYLES_XML.getFrom(options));
            ((org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart) stylesPart).setJaxbElement(styles);
            // NB - add it to main doc part, not package!
            documentPart.addTargetPart(stylesPart);
            assert documentPart.getStyleDefinitionsPart() != null : "Styles failed to set";
        }
        if (documentPart.getNumberingDefinitionsPart() == null) {
            // add it
            Part numberingPart = new org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart();
            final Numbering numbering = (Numbering) XmlUtils.unmarshalString(NUMBERING_XML.getFrom(options));
            ((org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart) numberingPart).setJaxbElement(numbering);
            // NB - add it to main doc part, not package!
            documentPart.addTargetPart(numberingPart);
            assert documentPart.getNumberingDefinitionsPart() != null : "Numbering failed to set";
        }
    } catch (InvalidFormatException e) {
        e.printStackTrace();
    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }
}
Also used : Numbering(org.docx4j.wml.Numbering) MainDocumentPart(org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart) Part(org.docx4j.openpackaging.parts.Part) MainDocumentPart(org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart) InvalidFormatException(org.docx4j.openpackaging.exceptions.InvalidFormatException) InvalidFormatException(org.docx4j.openpackaging.exceptions.InvalidFormatException) Docx4JException(org.docx4j.openpackaging.exceptions.Docx4JException) Styles(org.docx4j.wml.Styles)

Aggregations

Numbering (org.docx4j.wml.Numbering)2 Docx4JException (org.docx4j.openpackaging.exceptions.Docx4JException)1 InvalidFormatException (org.docx4j.openpackaging.exceptions.InvalidFormatException)1 Part (org.docx4j.openpackaging.parts.Part)1 MainDocumentPart (org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart)1 CTLongHexNumber (org.docx4j.wml.CTLongHexNumber)1 Jc (org.docx4j.wml.Jc)1 Lvl (org.docx4j.wml.Lvl)1 NumFmt (org.docx4j.wml.NumFmt)1 PPr (org.docx4j.wml.PPr)1 PPrBase (org.docx4j.wml.PPrBase)1 Ind (org.docx4j.wml.PPrBase.Ind)1 RFonts (org.docx4j.wml.RFonts)1 RPr (org.docx4j.wml.RPr)1 Styles (org.docx4j.wml.Styles)1