Create selected checkbox in MS word document

I would like to add a selected checkbox in a word document .I have tried using the Dynamic Word Document smart service to add a checkbox but it didn't work out .

Also using the MS word template smart service I found out a way to add a checkbox using the code below:

"<w:p>
<w:pPr>
<w:pStyle w:val=""NoSpacing""/>
<w:spacing w:before=""40"" w:after=""40""/>
<w:jc w:val=""center""/>
<w:rPr>
<w:rFonts w:ascii=""Arial"" w:hAnsi=""Arial"" w:cs=""Arial""/>
<w:sz w:val=""20""/>
<w:szCs w:val=""20""/>
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:rFonts w:ascii=""Arial"" w:hAnsi=""Arial"" w:cs=""Arial""/>
<w:sz w:val=""20""/>
<w:szCs w:val=""20""/>
</w:rPr>
<w:fldChar w:fldCharType=""begin"">
<w:ffData>
<w:name w:val=""""/>
<w:enabled/>
<w:calcOnExit w:val=""0""/>
<w:checkBox>
<w:sizeAuto/>
<w:default w:val="&char(34)&if(true(),"1","0")&char(34)&"/>
</w:checkBox>
</w:ffData>
</w:fldChar>
</w:r>
<w:r>
<w:rPr>
<w:rFonts w:ascii=""Arial"" w:hAnsi=""Arial"" w:cs=""Arial""/>
<w:sz w:val=""20""/>
<w:szCs w:val=""20""/>
</w:rPr>
<w:instrText xml:space=""preserve""> FORMCHECKBOX </w:instrText>
</w:r>

</w:p>"

 

But this code does not create a checkbox in word all the time.( I get an error saying  error at line 0 column 0   word/document.xml)

Has anybody else tried and was able to add a selected checkbox in word document?

attached sample word document.

 

 

testDocumentCheckbox.docx

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    Does it have to be a working checkbox, or do you just need to generate checked / unchecked boxes?

    This might seem like too much of a hack, but in case you would be OK with "dead" (i.e. not clickable) checkboxes, I have been using the following text strings perfectly for about 4 years now for our generated word documents:

    (unchecked box)
    </w:t><w:rPr><w:rFonts w:ascii='Wingdings' w:hAnsi='Wingdings'/><w:sz w:val='24'/><w:szCs w:val='22'/></w:rPr><w:t>o</w:t><w:t>

    (checked box)
    </w:t><w:rPr><w:rFonts w:ascii='Wingdings' w:hAnsi='Wingdings'/><w:sz w:val='24'/><w:szCs w:val='22'/></w:rPr><w:t>þ</w:t><w:t>

    Nevermind the fact that it changes the font to "Wingdings" to accomplish the affect - it looks really good and is sizeable. There might be a way to do this instead more straightforwardly with just Unicode character, but I haven't experimented with that yet.
    Hint: you can generate them in different sizes by changing the value of the "w:sz" tag. 24 ~ font size 12.

  • Thanks  for your help, I can create a checkbox using the above code. But after I have created the word document , I want to convert the word document into PDF but the checkbox dont get rendered in PDF it displays as ( o OR þ). In word it works fine but not in PDF after converting it.

  • 0
    Certified Lead Developer
    in reply to Larsen Rodrigues
    It sounds like during PDF conversion the font is being ignored. In this case the font is very important for the checkbox as we actually create these particular checkboxes by converting those characters you pasted to the Wingdings font where they render as the empty / filled checkboxes. If you're using an Appian based PDF convertor i'm unfamiliar with whether there's a way to force preservation of the font, but if you're using some other product to do the conversion then you might want to look into that.

    In any case, I've been meaning to look into whether it might be better to use certain Unicode characters for this instead of playing games with the font - so when I get some free time i'll look into that and let you know whether it seems to work.
  • 0
    Certified Lead Developer
    in reply to Larsen Rodrigues
    Please try these expressions to populate your checkboxes and let me know if the PDF conversion seems to work any better. These will use the unicode checked / unchecked box.

    (unchecked)
    "</w:t><w:rPr><w:rFonts w:ascii='Segoe UI Symbol' w:hAnsi='Segoe UI Symbol'/><w:sz w:val='24'/><w:szCs w:val='22'/></w:rPr><w:t>" & char(9744) & "</w:t><w:t>"

    (checked)
    "</w:t><w:rPr><w:rFonts w:ascii='Segoe UI Symbol' w:hAnsi='Segoe UI Symbol'/><w:sz w:val='24'/><w:szCs w:val='22'/></w:rPr><w:t>" & char(9745) & "</w:t><w:t>"
  • Hi  I tried the above code and in word document it works fine, but I am getting a # values in place of checkboxes in PDF.

Reply Children