Page 1 of 1

Adding Checkbox to document

PostPosted: Wed Apr 22, 2020 10:29 pm
by andres_s
Hi

I am having problems adding checkbox to document. Anything I do, it does not show up.

Here is my code of adding it to run:

Code: Select all
R run = factory.createR();

        CTFFCheckBox checkBox = factory.createCTFFCheckBox();

        BooleanDefaultTrue v = new BooleanDefaultTrue();
        v.setVal(bool.isValue());
        HpsMeasure measure = new HpsMeasure();
        measure.setVal(BigInteger.TEN);

        checkBox.setChecked(v);
        checkBox.setParent(run);
        checkBox.setSize(measure);
        checkBox.setDefault(v);

        JAXBElement<CTFFCheckBox> element = factory.createCTFFDataCheckBox(checkBox);

        Text t = factory.createText();
        t.setValue("test1");

        Text t2 = factory.createText();
        t2.setValue("test2");

        Text t3 = factory.createText();
        t3.setValue("test3");

        run.getContent().add(t);
        run.getContent().add(t2);
        run.getContent().add(element);

        run.getContent().add(t3);

        return run;



And resulting XML:

Code: Select all
<w:r>
    <w:rPr>
       <w:rFonts/>
       <w:sz w:val="16"/>
       <w:szCs w:val="16"/>
   </w:rPr>
   <w:t>test1</w:t>
   <w:t>test2</w:t>
   <w:t>test3</w:t>
</w:r>




Does anyone have had success with creating a CheckBox before? Any help is highly appriciated.

Re: Adding Checkbox to document

PostPosted: Thu Apr 23, 2020 8:42 am
by jason
There are 4 types of checkbox.

First is a checkbox glyph.

Second is a content control checkbox.

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
        <w:sdt>
            <w:sdtPr>
                <w:id w:val="1092049435"/>
                <w14:checkbox>
                    <w14:checked w14:val="0"/>
                    <w14:checkedState w14:font="MS Gothic" w14:val="2612"/>
                    <w14:uncheckedState w14:font="MS Gothic" w14:val="2610"/>
                </w14:checkbox>
            </w:sdtPr>
            <w:sdtContent>
                <w:p w:rsidR="00000000" w:rsidRDefault="00FD2C55">
                    <w:r>
                        <w:rPr>
                            <w:rFonts w:ascii="MS Gothic" w:eastAsia="MS Gothic" w:hAnsi="MS Gothic" w:hint="eastAsia"/>
                        </w:rPr>
                        <w:t></w:t>
                    </w:r>
                </w:p>
            </w:sdtContent>
        </w:sdt>
 
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


The above are generally to be preferred. The other two are legacy approaches... below I've created them in Word then used the Docx4j Helper Word AddIn to generate code (you could use the webapp instead).

The first legacy approach is FORMCHECKBOX (the type you look like you want), for example:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
        <w:p w:rsidR="00000000" w:rsidRDefault="00304D34">
            <w:r>
                <w:fldChar w:fldCharType="begin">
                    <w:ffData>
                        <w:name w:val="Check1"/>
                        <w:enabled/>
                        <w:calcOnExit w:val="false"/>
                        <w:checkBox>
                            <w:sizeAuto/>
                            <w:default w:val="false"/>
                        </w:checkBox>
                    </w:ffData>
                </w:fldChar>
            </w:r>
            <w:bookmarkStart w:id="0" w:name="Check1"/>
            <w:r>
                <w:instrText xml:space="preserve"> FORMCHECKBOX </w:instrText>
            </w:r>
            <w:r>
                <w:fldChar w:fldCharType="end"/>
            </w:r>
            <w:bookmarkEnd w:id="0"/>
        </w:p>
 
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


Note the bookmark. You could leave that out, I think.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting

import org.docx4j.wml.CTColumns;
import org.docx4j.wml.CTFFCheckBox;
import org.docx4j.wml.CTFFData;
import org.docx4j.wml.CTFFName;
import org.docx4j.wml.FldChar;

import org.docx4j.wml.CTBookmark;
import org.docx4j.wml.CTMarkupRange;

        // Assume P p
            // Create object for r
            R r = wmlObjectFactory.createR();
            p.getContent().add( r);
                // Create object for fldChar (wrapped in JAXBElement)
                FldChar fldchar = wmlObjectFactory.createFldChar();
                JAXBElement<org.docx4j.wml.FldChar> fldcharWrapped = wmlObjectFactory.createRFldChar(fldchar);
                r.getContent().add( fldcharWrapped);
                    fldchar.setFldCharType(org.docx4j.wml.STFldCharType.BEGIN);
                    // Create object for ffData
                    CTFFData ffdata = wmlObjectFactory.createCTFFData();
                    fldchar.setFfData(ffdata);
                        // Create object for name (wrapped in JAXBElement)
                        CTFFName ffname = wmlObjectFactory.createCTFFName();
                        JAXBElement<org.docx4j.wml.CTFFName> ffnameWrapped = wmlObjectFactory.createCTFFDataName(ffname);
                        ffdata.getNameOrEnabledOrCalcOnExit().add( ffnameWrapped);
                            ffname.setVal( "Check1");
                        // Create object for enabled (wrapped in JAXBElement)
                        BooleanDefaultTrue booleandefaulttrue = wmlObjectFactory.createBooleanDefaultTrue();
                        JAXBElement<org.docx4j.wml.BooleanDefaultTrue> booleandefaulttrueWrapped = wmlObjectFactory.createCTFFDataEnabled(booleandefaulttrue);
                        ffdata.getNameOrEnabledOrCalcOnExit().add( booleandefaulttrueWrapped);
                        // Create object for calcOnExit (wrapped in JAXBElement)
                        BooleanDefaultTrue booleandefaulttrue2 = wmlObjectFactory.createBooleanDefaultTrue();
                        JAXBElement<org.docx4j.wml.BooleanDefaultTrue> booleandefaulttrueWrapped2 = wmlObjectFactory.createCTFFDataCalcOnExit(booleandefaulttrue2);
                        ffdata.getNameOrEnabledOrCalcOnExit().add( booleandefaulttrueWrapped2);
                        // Create object for checkBox (wrapped in JAXBElement)
                        CTFFCheckBox ffcheckbox = wmlObjectFactory.createCTFFCheckBox();
                        JAXBElement<org.docx4j.wml.CTFFCheckBox> ffcheckboxWrapped = wmlObjectFactory.createCTFFDataCheckBox(ffcheckbox);
                        ffdata.getNameOrEnabledOrCalcOnExit().add( ffcheckboxWrapped);
                            // Create object for sizeAuto
                            BooleanDefaultTrue booleandefaulttrue3 = wmlObjectFactory.createBooleanDefaultTrue();
                            ffcheckbox.setSizeAuto(booleandefaulttrue3);
                            // Create object for default
                            BooleanDefaultTrue booleandefaulttrue4 = wmlObjectFactory.createBooleanDefaultTrue();
                            ffcheckbox.setDefault(booleandefaulttrue4);
            // Create object for bookmarkStart (wrapped in JAXBElement)
            CTBookmark bookmark = wmlObjectFactory.createCTBookmark();
            JAXBElement<org.docx4j.wml.CTBookmark> bookmarkWrapped = wmlObjectFactory.createPBookmarkStart(bookmark);
            p.getContent().add( bookmarkWrapped);
                bookmark.setName( "Check1");
                bookmark.setId( BigInteger.valueOf( 0) );
            // Create object for r
            R r2 = wmlObjectFactory.createR();
            p.getContent().add( r2);
                // Create object for instrText (wrapped in JAXBElement)
                Text text = wmlObjectFactory.createText();
                JAXBElement<org.docx4j.wml.Text> textWrapped = wmlObjectFactory.createRInstrText(text);
                r2.getContent().add( textWrapped);
                    text.setValue( " FORMCHECKBOX ");
                    text.setSpace( "preserve");
            // Create object for r
            R r3 = wmlObjectFactory.createR();
            p.getContent().add( r3);
                // Create object for fldChar (wrapped in JAXBElement)
                FldChar fldchar2 = wmlObjectFactory.createFldChar();
                JAXBElement<org.docx4j.wml.FldChar> fldcharWrapped2 = wmlObjectFactory.createRFldChar(fldchar2);
                r3.getContent().add( fldcharWrapped2);
                    fldchar2.setFldCharType(org.docx4j.wml.STFldCharType.END);
            // Create object for bookmarkEnd (wrapped in JAXBElement)
            CTMarkupRange markuprange = wmlObjectFactory.createCTMarkupRange();
            JAXBElement<org.docx4j.wml.CTMarkupRange> markuprangeWrapped = wmlObjectFactory.createPBookmarkEnd(markuprange);
            p.getContent().add( markuprangeWrapped);
                markuprange.setId( BigInteger.valueOf( 0) );
 
Parsed in 0.023 seconds, using GeSHi 1.0.8.4


The second is an ActiveX checkbox

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
           <w:r>
                <w:object w:dxaOrig="1440" w:dyaOrig="1440">
                    <v:shapetype xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:v="urn:schemas-microsoft-com:vml" coordsize="21600,21600" filled="f" id="_x0000_t75" path="m@4@5l@4@11@9@11@9@5xe" stroked="f" o:preferrelative="t" o:spt="75.0">
                        <v:stroke joinstyle="miter"/>
                        <v:formulas>
                            <v:f eqn="if lineDrawn pixelLineWidth 0"/>
                            <v:f eqn="sum @0 1 0"/>
                            <v:f eqn="sum 0 0 @1"/>
                            <v:f eqn="prod @2 1 2"/>
                            <v:f eqn="prod @3 21600 pixelWidth"/>
                            <v:f eqn="prod @3 21600 pixelHeight"/>
                            <v:f eqn="sum @0 0 1"/>
                            <v:f eqn="prod @6 1 2"/>
                            <v:f eqn="prod @7 21600 pixelWidth"/>
                            <v:f eqn="sum @8 21600 0"/>
                            <v:f eqn="prod @7 21600 pixelHeight"/>
                            <v:f eqn="sum @10 21600 0"/>
                        </v:formulas>
                        <v:path gradientshapeok="t" o:connecttype="rect" o:extrusionok="f"/>
                        <o:lock aspectratio="t" v:ext="edit"/>
                    </v:shapetype>
                    <v:shape xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:v="urn:schemas-microsoft-com:vml" id="_x0000_i1025" style="width:108.3pt;height:20.75pt" type="#_x0000_t75" o:ole="">
                        <v:imagedata xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:id="rId4" o:title=""/>
                    </v:shape>
                    <w:control xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:id="rId5" w:name="CheckBox1" w:shapeid="_x0000_i1025"/>
                </w:object>
            </w:r>
 
Parsed in 0.004 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
        // Assume P p
           // Create object for r
            R r = wmlObjectFactory.createR();
                // Create object for object (wrapped in JAXBElement)
                CTObject object = wmlObjectFactory.createCTObject();
                JAXBElement<org.docx4j.wml.CTObject> objectWrapped = wmlObjectFactory.createRObject(object);
                r.getContent().add( objectWrapped);
                    // Create object for control
                    CTControl control = wmlObjectFactory.createCTControl();
                    object.setControl(control);
                        control.setName( "CheckBox1");
                        control.setShapeid( "_x0000_i1025");
                        control.setId( "rId5");
                    object.setDxaOrig( BigInteger.valueOf( 1440) );
                    object.setDyaOrig( BigInteger.valueOf( 1440) );
org.docx4j.vml.ObjectFactory vmlObjectFactory = new org.docx4j.vml.ObjectFactory();
                    // Create object for shapetype (wrapped in JAXBElement)
                    CTShapetype shapetype = vmlObjectFactory.createCTShapetype();
                    JAXBElement<org.docx4j.vml.CTShapetype> shapetypeWrapped = vmlObjectFactory.createShapetype(shapetype);
                    object.getAnyAndAny().add( shapetypeWrapped);
                        // Create object for stroke (wrapped in JAXBElement)
                        CTStroke stroke = vmlObjectFactory.createCTStroke();
                        JAXBElement<org.docx4j.vml.CTStroke> strokeWrapped = vmlObjectFactory.createStroke(stroke);
                        shapetype.getEGShapeElements().add( strokeWrapped);
                            stroke.setJoinstyle(org.docx4j.vml.STStrokeJoinStyle.MITER);
                        // Create object for formulas (wrapped in JAXBElement)
                        CTFormulas formulas = vmlObjectFactory.createCTFormulas();
                        JAXBElement<org.docx4j.vml.CTFormulas> formulasWrapped = vmlObjectFactory.createFormulas(formulas);
                        shapetype.getEGShapeElements().add( formulasWrapped);
                            // Create object for f
                            CTF f = vmlObjectFactory.createCTF();
                            formulas.getF().add( f);
                                f.setEqn( "if lineDrawn pixelLineWidth 0");
                            // Create object for f
                            CTF f2 = vmlObjectFactory.createCTF();
                            formulas.getF().add( f2);
                                f2.setEqn( "sum @0 1 0");
                            // Create object for f
                            CTF f3 = vmlObjectFactory.createCTF();
                            formulas.getF().add( f3);
                                f3.setEqn( "sum 0 0 @1");
                            // Create object for f
                            CTF f4 = vmlObjectFactory.createCTF();
                            formulas.getF().add( f4);
                                f4.setEqn( "prod @2 1 2");
                            // Create object for f
                            CTF f5 = vmlObjectFactory.createCTF();
                            formulas.getF().add( f5);
                                f5.setEqn( "prod @3 21600 pixelWidth");
                            // Create object for f
                            CTF f6 = vmlObjectFactory.createCTF();
                            formulas.getF().add( f6);
                                f6.setEqn( "prod @3 21600 pixelHeight");
                            // Create object for f
                            CTF f7 = vmlObjectFactory.createCTF();
                            formulas.getF().add( f7);
                                f7.setEqn( "sum @0 0 1");
                            // Create object for f
                            CTF f8 = vmlObjectFactory.createCTF();
                            formulas.getF().add( f8);
                                f8.setEqn( "prod @6 1 2");
                            // Create object for f
                            CTF f9 = vmlObjectFactory.createCTF();
                            formulas.getF().add( f9);
                                f9.setEqn( "prod @7 21600 pixelWidth");
                            // Create object for f
                            CTF f10 = vmlObjectFactory.createCTF();
                            formulas.getF().add( f10);
                                f10.setEqn( "sum @8 21600 0");
                            // Create object for f
                            CTF f11 = vmlObjectFactory.createCTF();
                            formulas.getF().add( f11);
                                f11.setEqn( "prod @7 21600 pixelHeight");
                            // Create object for f
                            CTF f12 = vmlObjectFactory.createCTF();
                            formulas.getF().add( f12);
                                f12.setEqn( "sum @10 21600 0");
                        // Create object for path (wrapped in JAXBElement)
                        CTPath path = vmlObjectFactory.createCTPath();
                        JAXBElement<org.docx4j.vml.CTPath> pathWrapped = vmlObjectFactory.createPath(path);
                        shapetype.getEGShapeElements().add( pathWrapped);
                            path.setGradientshapeok(org.docx4j.vml.STTrueFalse.T);
                            path.setConnecttype(org.docx4j.vml.officedrawing.STConnectType.RECT);
                            path.setExtrusionok(org.docx4j.vml.officedrawing.STTrueFalse.F);
org.docx4j.vml.officedrawing.ObjectFactory vmlofficedrawingObjectFactory = new org.docx4j.vml.officedrawing.ObjectFactory();
                        // Create object for lock (wrapped in JAXBElement)
                        CTLock lock = vmlofficedrawingObjectFactory.createCTLock();
                        JAXBElement<org.docx4j.vml.officedrawing.CTLock> lockWrapped = vmlofficedrawingObjectFactory.createLock(lock);
                        shapetype.getEGShapeElements().add( lockWrapped);
                            lock.setAspectratio(org.docx4j.vml.officedrawing.STTrueFalse.T);
                            lock.setExt(org.docx4j.vml.STExt.EDIT);
                        shapetype.setStroked(org.docx4j.vml.STTrueFalse.F);
                        shapetype.setFilled(org.docx4j.vml.STTrueFalse.F);
                        shapetype.setSpt( new Float(75.0) );
                        shapetype.setConnectortype(org.docx4j.vml.officedrawing.STConnectorType.STRAIGHT);
                        shapetype.setPreferrelative(org.docx4j.vml.officedrawing.STTrueFalse.T);
                        shapetype.setPath( "m@4@5l@4@11@9@11@9@5xe");
                        shapetype.setCoordsize( "21600,21600");
                        shapetype.setVmlId( "_x0000_t75");
                        shapetype.setHralign(org.docx4j.vml.officedrawing.STHrAlign.LEFT);
                        shapetype.setInsetmode(org.docx4j.vml.officedrawing.STInsetMode.CUSTOM);
                    // Create object for shape (wrapped in JAXBElement)
                    CTShape shape = vmlObjectFactory.createCTShape();
                    JAXBElement<org.docx4j.vml.CTShape> shapeWrapped = vmlObjectFactory.createShape(shape);
                    object.getAnyAndAny().add( shapeWrapped);
                        shape.setVmlId( "_x0000_i1025");
                        shape.setType( "#_x0000_t75");
                        shape.setStyle( "width:108.3pt;height:20.75pt");
                        // Create object for imagedata (wrapped in JAXBElement)
                        CTImageData imagedata = vmlObjectFactory.createCTImageData();
                        JAXBElement<org.docx4j.vml.CTImageData> imagedataWrapped = vmlObjectFactory.createImagedata(imagedata);
                        shape.getEGShapeElements().add( imagedataWrapped);
                            imagedata.setId( "rId4");
                            imagedata.setTitle( "");
                        shape.setHralign(org.docx4j.vml.officedrawing.STHrAlign.LEFT);
                        shape.setInsetmode(org.docx4j.vml.officedrawing.STInsetMode.CUSTOM);
                        shape.setConnectortype(org.docx4j.vml.officedrawing.STConnectorType.STRAIGHT);
                        shape.setOle( "");
 
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

Re: Adding Checkbox to document

PostPosted: Thu Apr 23, 2020 6:22 pm
by andres_s
Thank you for your quick reply! However looking at document.xml I need Content Control Checkboxes, not legacy. Other checkboxes (added via MS Word) look like this:

Code: Select all
                                <w:sdt>
                                    <w:sdtPr>
                                        <w:id w:val="1477646757"/>
                                        <w14:checkbox>
                                            <w14:checked w14:val="1"/>
                                            <w14:checkedState w14:font="MS Gothic" w14:val="2612"/>
                                            <w14:uncheckedState w14:font="MS Gothic" w14:val="2610"/>
                                        </w14:checkbox>
                                    </w:sdtPr>
                                    <w:sdtContent>
                                        <w:r>
                                            <w:rPr>
                                                <w:rFonts w:hint="eastAsia" w:ascii="MS Gothic" w:hAnsi="MS Gothic" w:eastAsia="MS Gothic"/>
                                            </w:rPr>
                                            <w:t>☒</w:t>
                                        </w:r>
                                    </w:sdtContent>
                                </w:sdt>



However I am unable to replicate this in Java code. Any pointer for achieving that?

Re: Adding Checkbox to document

PostPosted: Sun Apr 26, 2020 8:28 am
by jason
Output of docx4j webapp code gen, edited slightly, untested:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
import java.math.BigInteger;
import javax.xml.bind.JAXBElement;
import org.docx4j.w14.CTOnOff;
import org.docx4j.w14.CTSdtCheckbox;
import org.docx4j.w14.CTSdtCheckboxSymbol;
import org.docx4j.wml.Id;
import org.docx4j.wml.SdtBlock;
import org.docx4j.wml.SdtPr;


public class Foo {
public SdtBlock createIt() {

org.docx4j.wml.ObjectFactory wmlObjectFactory = new org.docx4j.wml.ObjectFactory();

SdtBlock sdtblock = wmlObjectFactory.createSdtBlock();
    // Create object for sdtPr
    SdtPr sdtpr = wmlObjectFactory.createSdtPr();
    sdtblock.setSdtPr(sdtpr);
org.docx4j.w14.ObjectFactory w14ObjectFactory = new org.docx4j.w14.ObjectFactory();
        // Create object for checkbox (wrapped in JAXBElement)
        CTSdtCheckbox sdtcheckbox = w14ObjectFactory.createCTSdtCheckbox();
        JAXBElement<org.docx4j.w14.CTSdtCheckbox> sdtcheckboxWrapped = w14ObjectFactory.createCheckbox(sdtcheckbox);
        sdtpr.getRPrOrAliasOrLock().add( sdtcheckboxWrapped);
            // Create object for checked
            CTOnOff onoff = w14ObjectFactory.createCTOnOff();
            sdtcheckbox.setChecked(onoff);
                onoff.setVal( "1");
            // Create object for uncheckedState
            CTSdtCheckboxSymbol sdtcheckboxsymbol = w14ObjectFactory.createCTSdtCheckboxSymbol();
            sdtcheckbox.setUncheckedState(sdtcheckboxsymbol);
                sdtcheckboxsymbol.setVal( "2610");
                sdtcheckboxsymbol.setFont( "MS Gothic");
            // Create object for checkedState
            CTSdtCheckboxSymbol sdtcheckboxsymbol2 = w14ObjectFactory.createCTSdtCheckboxSymbol();
            sdtcheckbox.setCheckedState(sdtcheckboxsymbol2);
                sdtcheckboxsymbol2.setVal( "2612");
                sdtcheckboxsymbol2.setFont( "MS Gothic");
        // Create object for id
        Id id2 = wmlObjectFactory.createId();
        sdtpr.setId(id2);
            id2.setVal( BigInteger.valueOf( 1477646757) );

return sdtblock;
}
}
 
Parsed in 0.018 seconds, using GeSHi 1.0.8.4


Code gen via the Word AddIn didn't support the w14 elements, I'll need to give it some love.

Re: Adding Checkbox to document

PostPosted: Mon Apr 27, 2020 6:38 pm
by andres_s
Thank you for your reply! I finally got it to work with few additions. Here is my final code:

Code: Select all
    private static ObjectFactory factory = new org.docx4j.wml.ObjectFactory();
    private static org.docx4j.w14.ObjectFactory w14ObjectFactory = new org.docx4j.w14.ObjectFactory();

private SdtBlock createCheckboxSdtBlock(boolean isChecked) {
        SdtBlock sdtblock = factory.createSdtBlock();

        SdtPr sdtpr = factory.createSdtPr();
        sdtblock.setSdtPr(sdtpr);

        CTSdtCheckbox sdtcheckbox = w14ObjectFactory.createCTSdtCheckbox();
        JAXBElement<CTSdtCheckbox> sdtcheckboxWrapped = w14ObjectFactory.createCheckbox(sdtcheckbox);
        sdtpr.getRPrOrAliasOrLock().add(sdtcheckboxWrapped);

        CTOnOff onoff = w14ObjectFactory.createCTOnOff();
        sdtcheckbox.setChecked(onoff);
        onoff.setVal(isChecked ? "1" : "0");

        CTSdtCheckboxSymbol sdtcheckboxsymbol = w14ObjectFactory.createCTSdtCheckboxSymbol();
        sdtcheckbox.setUncheckedState(sdtcheckboxsymbol);
        sdtcheckboxsymbol.setVal("2610");
        sdtcheckboxsymbol.setFont("MS Gothic");

        CTSdtCheckboxSymbol sdtcheckboxsymbol2 = w14ObjectFactory.createCTSdtCheckboxSymbol();
        sdtcheckbox.setCheckedState(sdtcheckboxsymbol2);
        sdtcheckboxsymbol2.setVal("2612");
        sdtcheckboxsymbol2.setFont("MS Gothic");

        Id id2 = factory.createId();
        sdtpr.setId(id2);
        id2.setVal(BigInteger.valueOf(1487646757));


        SdtContentBlock contentBlock = factory.createSdtContentBlock();
        R run = factory.createR();
        RPr rPr = factory.createRPr();

        RFonts rFonts = factory.createRFonts();
        rFonts.setAscii("MS Gothic");
        rFonts.setHint(STHint.EAST_ASIA);
        rFonts.setHAnsi("MS Gothic");
        rFonts.setEastAsia("MS Gothic");

        rPr.setRFonts(rFonts);

        run.getContent().add(rPr);

        Text t = factory.createText();

        t.setValue(isChecked ? "☒" : "☐");
        run.getContent().add(t);

        contentBlock.getContent().add(run);
        sdtblock.setSdtContent(contentBlock);

        return sdtblock;




Thanks a lot for help, Jason!