4

Please help me out, I have two doubts in fop pdf generation

  1. How to include font-awesome icons or utf characters in FOP based pdf generation

  2. apply color based on the value.

Please help me

Any suggestions are accepted.

fabian
  • 67,623
  • 12
  • 74
  • 102
Manikanta Reddy
  • 781
  • 5
  • 21

1 Answers1

4

You can use Font Awesome just like any other font:

  1. in the FO file, set the font-family property on the fo:block (or fo:inline, ...) containing the Unicode entities for the icons you need
  2. create/edit a FOP configuration file to map the font-family value to the TrueType font file contained in the Font Awesome distribution
  3. tell FOP to use your configuration file

As for the color, you can use the properties color and background-color to set the glyphs font color and background color.

An example, tested with FOP 2.0:

FO fragment

<fo:block>
    Icons:
    <fo:inline font-family="FontAwesome">
        &#xf13d; &#xf242; &#xf02d; &#xf27b;
    </fo:inline>
</fo:block>
<fo:block>
    Coloured icons:
    <fo:inline font-family="FontAwesome" color="#AA0000">
        &#xf13d; &#xf242; &#xf02d; &#xf27b;
    </fo:inline>
</fo:block>
<fo:block>
    Coloured icons with background:
    <fo:inline font-family="FontAwesome" color="#FFFFFF" background-color="#AA0000">
        &#xf13d; &#xf242; &#xf02d; &#xf27b;
    </fo:inline>
</fo:block>

FOP configuration fragment:

<renderer mime="application/pdf">
  ...
  <fonts>
    <font embed-url="/Users/furini/font-awesome-4.4.0/fonts/fontawesome-webfont.ttf">
      <font-triplet name="FontAwesome" style="normal" weight="normal"/>
    </font>
    ...
  </fonts>
  ...
</renderer>

Output:

PDF output screenshot

Note that you get a warning, but it's nothing to worry about (it just tells you that Font Awesome does not have a glyph for the default hyphenation character, but you are not going to use hyphenation with icons anyway!):

25-ott-2015 13.31.38 org.apache.fop.fo.properties.CommonHyphenation getHyphChar
WARNING: Substituted specified hyphenation character (0x2d) with 0x20 because the font doesn't have the specified hyphenation character: FontAwesome,normal,400

(this old answer of mine gives some more details about font configuration and the errors/warnings you could get)

(disclosure: I'm a FOP developer, though not very active nowadays)

lfurini
  • 3,420
  • 4
  • 27
  • 40