Search code examples
xmlxsltxslt-1.0xsl-fo

Adding Square Check Boxes in XSL:FO


Looking to see if there is a way of using XSL:FO to create a square box. Ultimately the document I am trying to create will have a box drawn for the end user to be able to "tick" manually from the printed document...

Check box example

I am aware this task could be done using tables and utilizing the borders, but my goal would be to have the box the same size or smaller then the font next to it, where the table would usually be greater then the size of the text. Could also consider an image that is a square box, but thinking there is a better way then just inserting an image.

(Using xsl version 1.0)


Solution

  • Use a glyph from a specific font ... like U+2610 Ballot Box. Find a font that contains the character and use it. You can even put that character into an fo:inline and adjust the font size to be whatever you like:

    ☐ This is the character

    For example -- using charmap and searching "ballot" shows the following characters inside that font:

    enter image description here

    You want the empty one which shows U+2610 is the code. If you have Arial Unicode font on the machine and you have it mapped in Apache FOP, you would use:

    <fo:inline font-family="Arial Unicode">☐</fo:inline>
    

    Or of course you could use the character entity. This is a great site also for finding out which glyphs are in which common fonts:

    http://www.fileformat.info/info/unicode/char/2610/fontsupport.htm