4

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)

2 Answers2

2

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

Kevin Brown
  • 8,194
  • 2
  • 14
  • 34
  • I'm having trouble getting this to execute the character symbol.... - this is not working (Using FOP 1.1) – Alistair Lindsay-Macfadyen Jan 15 '16 at 05:56
  • That is because the glyph does not exist in the Symbol font. You must specify and properly reference a font that it does exist in. – Kevin Brown Jan 15 '16 at 06:22
  • A formatting engine needs several things to format a specific character -- (1) You specify that character in the text, (2) you specify the font you wish that character rendered in and (3) you make the formatting engine aware of that exact font. Just putting the character in some text (which is #1) is two steps short of getting the job done. – Kevin Brown Jan 15 '16 at 06:26
  • What type of Symbol font are you using? Open type, true type, or type1 font? – Joel M. Lamsen Jan 15 '16 at 07:07
  • You could use any font that has the glyph. I looked it up using charmap on Windows in Arial Unicorn which is true type font. That character is also in MS Gothic and many other fonts. – Kevin Brown Jan 15 '16 at 18:17
  • I added more info to the answer to show what I mean. – Kevin Brown Jan 15 '16 at 19:13
  • In case some help is needed to configure the fonts for FOP, [this old answer of mine](http://stackoverflow.com/a/28251945/4453460) could come in handy. – lfurini Jan 16 '16 at 10:59
  • Thanks Kevin for the further clarification, I have cut and paste your line of code and that still did not work, even once i changed the following lines in my XSL file, and also , but this was still unsuccessful. also looked up more forums about using Unicode in the text, I have used the Simple ASCII before successfully, but not the Unicode. – Alistair Lindsay-Macfadyen Jan 17 '16 at 23:20
  • My line of code would only work if you setup FOP to use Arial Unicode font and you named it that exact name. Why not expand your question a bit with how you have changed you font settings so we can see what is wrong. – Kevin Brown Jan 17 '16 at 23:35
  • Kevin's solution is correct, but this did not in fact solve my issue, I went back to my developers and we found some issues with regards to the FOP library we were using, it could not access the Arial Unicode MS fonts locally, and my XSL file (whilst saying it was UTF-8 encoding) was still saved in an ASCII format. – Alistair Lindsay-Macfadyen Jan 19 '16 at 20:57
0

You can use an inline element with a border, like this:

<fo:block>
    Yes
    <fo:inline border-style="solid" border-width="1pt">&#160;&#160;&#160;&#160;</fo:inline>
    &#160;&#160;&#160;&#160;
    No 
    <fo:inline border-style="solid" border-width="1pt">&#160;&#160;&#160;&#160;</fo:inline>
</fo:block>

&#160; is used for spacing

True Soft
  • 8,246
  • 6
  • 48
  • 77