title: Embedding Font into Apache FOP
body: <p>I am tring to get Apache FOP to use Arial as font. So far, without luck.</p>
  
  <p>In my config.xml it says:</p>
  
  <pre><code>&lt;fonts&gt;                           
   &lt;font kerning="yes"  embed-url="file:///C:/Windows/Fonts/Arial.ttf" encoding-mode="auto"&gt;&gt;
  &lt;font-triplet name="Arial" style="normal" weight="normal"/&gt;
   &lt;/font&gt;                     
  &lt;/fonts&gt;
  </code></pre>
  
  <p>But it doesnt seem to work. When I start FOP on the command line it says font Arial normal not found.</p>
  
  <p>I have tried to generate the Arial.xml file from the ttf with TTFReader in FOP but that, too, hasnt worked (even following the instructions on the fop webpage).
  I get the following error message:</p>
  
  <pre><code>C:\Users\xy\Desktop\FOP2&gt;java -cp build\fop.jar;lib\avalon-framework-4.2.0.jar;lib\commons-logging-1.0.4.jar;lib\commons-io-1.3.1.jar org.apache.fop.TTFReader C:\Windows\Fonts\arial.ttf Arial.xml
  TTF Reader for Apache FOP 1.1
  
  Parsing font...
  Reading C:\Windows\Fonts\arial.ttf...
  Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlgraphics/fonts/Glyphs
          at org.apache.fop.fonts.truetype.TTFFile.initAnsiWidths(TTFFile.java:662)
          at org.apache.fop.fonts.truetype.TTFFile.readFont(TTFFile.java:711)
          at org.apache.fop.fonts.apps.TTFReader.loadTTF(TTFReader.java:224)
          at org.apache.fop.fonts.apps.TTFReader.main(TTFReader.java:177)
  Caused by: java.lang.ClassNotFoundException: org.apache.xmlgraphics.fonts.Glyphs
          at java.net.URLClassLoader$1.run(Unknown Source)
          at java.net.URLClassLoader$1.run(Unknown Source)
          at java.security.AccessController.doPrivileged(Native Method)
          at java.net.URLClassLoader.findClass(Unknown Source)
          at java.lang.ClassLoader.loadClass(Unknown Source)
          at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
          at java.lang.ClassLoader.loadClass(Unknown Source)
  </code></pre>
  
  <p>Maybe Im not seeing the forrest for the trees, but I'm at a loss as to what to do.</p>
  
  <p>Any suggestions?</p>
  
  <p>UDPDATE:</p>
  
  <ul>
  <li>I downloaded a lot of xml-Files from this site:
  <a href="http://www.java2s.com/Code/Jar/f/Downloadfopfontmetricsjar.htm" rel="noreferrer">http://www.java2s.com/Code/Jar/f/Downloadfopfontmetricsjar.htm</a>
  (which to me look a lot like the xml-files that were already in fop. so I assume they are in the correct format)</li>
  </ul>
  
  <p>I put them in the folder fop/src/codegen</p>
  
  <p>I also put the arial.tff there</p>
  
  <p>in the file fop/conf/xconf it says</p>
  
  <pre><code>&lt;fonts&gt;
  
        &lt;directory&gt;C:\Windows\Fonts&lt;/directory&gt;
          &lt;!-- embedded fonts --&gt;
          &lt;!--
          This information must exactly match the font specified
          in the fo file. Otherwise it will use a default font.
  
          For example,
          &lt;fo:inline font-family="Arial" font-weight="bold" font-style="normal"&gt;
              Arial-normal-normal font
          &lt;/fo:inline&gt;
          for the font triplet specified by:
          &lt;font-triplet name="Arial" style="normal" weight="bold"/&gt;
  
          If you do not want to embed the font in the pdf document
          then do not include the "embed-url" attribute.
          The font will be needed where the document is viewed
          for it to be displayed properly.
  
          possible styles: normal | italic | oblique | backslant
          possible weights: normal | bold | 100 | 200 | 300 | 400
                            | 500 | 600 | 700 | 800 | 900
          (normal = 400, bold = 700)
          --&gt;
  
          &lt;font metrics-url="C:\Users\z003a5bp\Desktop\FOP2\src\codegen\fonts\arial.xml" kerning="yes" embed-url="C:\Users\z003a5bp\Desktop\FOP2\src\codegen\fonts\arial.ttf"&gt;
            &lt;font-triplet name="Arial" style="normal" weight="normal"/&gt;
            &lt;!-- &lt;font-triplet name="ArialMT" style="normal" weight="normal"/&gt; --&gt;
          &lt;/font&gt;
         &lt;!-- &lt;font metrics-url="arialb.xml" kerning="yes" embed-url="arialb.ttf"&gt;
            &lt;font-triplet name="Arial" style="normal" weight="bold"/&gt;
            &lt;font-triplet name="ArialMT" style="normal" weight="bold"/&gt; --&gt;
  
            &lt;auto-detect/&gt;
        &lt;/fonts&gt;
  </code></pre>
  
  <p>So ive got auto-detec and specified a directory for the fonts and embedded arial - stil I get error messages like "glyph xyz is not included in Helvetica" although nowhere in my stylesheets does it say font-family Helvetica. The pdfs are displayed in Times New Roman...</p>
  
  <p>++ UPDATE ++ </p>
  
  <p>Okay...</p>
  
  <p>my fop.xconf file says this now:</p>
  
  <pre><code>&lt;fop version="1.0"&gt;
  
    &lt;base&gt;.&lt;/base&gt;
  
    &lt;source-resolution&gt;72&lt;/source-resolution&gt;
    &lt;target-resolution&gt;72&lt;/target-resolution&gt;
    &lt;default-page-settings height="11in" width="8.26in"/&gt;
    &lt;renderers&gt;
      &lt;renderer mime="application/pdf"&gt;
        &lt;filterList&gt;
          &lt;value&gt;flate&lt;/value&gt;
        &lt;/filterList&gt;
  
        &lt;fonts&gt;
  
         &lt;font metrics-url="file:///C:/Users/z003a5bp/Desktop/FOP2/src/codegen/fonts/arial.xml"
              kerning="yes"
              embed-url="file:///C:/Users/z003a5bp/Desktop/FOP2/arial.ttf"&gt;
          &lt;font-triplet name="Arial" style="normal" weight="normal"/&gt;
              &lt;/font&gt; 
  
            &lt;auto-detect/&gt;
        &lt;/fonts&gt;
  
      &lt;/renderer&gt;
  </code></pre>
  
  <p>I've added font-family="Arial" to pretty much all the elements now :D</p>
  
  <p>I go to my fop directory in the command line and enter</p>
  
  <pre><code>fop -xml blabla\file.xml -xsl blabla\stylesheet.xsl -pdf output.pdf
  </code></pre>
  
  <p>And i get the following:</p>
  
  <pre><code>Nov 07, 2013 1:34:29 PM org.apache.fop.events.LoggingEventListener processEvent
  Schwerwiegend: Image not found. URI: 15300145419.PNG. (See position 44:-1)
  Nov 07, 2013 1:34:29 PM org.apache.fop.events.LoggingEventListener processEvent
  Warnung: The following feature isn't implemented by Apache FOP, yet: table-layout="auto" (on fo:table) (Siehe Position 29:-1)
  Nov 07, 2013 1:34:29 PM org.apache.fop.events.LoggingEventListener processEvent
  Schwerwiegend: Image not found. URI: 15627351051.PNG. (See position 44:-1)
  Nov 07, 2013 1:34:29 PM org.apache.fop.events.LoggingEventListener processEvent
  Schwerwiegend: Image not found. URI: 15629782795.PNG. (See position 44:-1)
  Nov 07, 2013 1:34:29 PM org.apache.fop.events.LoggingEventListener processEvent
  Warnung: Font "Arial,normal,400" not found. Substituting with "any,normal,400".
  Nov 07, 2013 1:34:29 PM org.apache.fop.events.LoggingEventListener processEvent
  Warnung: Glyph "?" (0x95) not available in font "Times-Roman".
  Nov 07, 2013 1:34:29 PM org.apache.fop.events.LoggingEventListener processEvent
  Warnung: Font "Arial,italic,400" not found. Substituting with "any,italic,400".
  Nov 07, 2013 1:34:29 PM org.apache.fop.events.LoggingEventListener processEvent
  Warnung: Content overflows the viewport of the fo:region-before on page 1 in block-progression direction by 2989 millipoints. (See position 50:-1)
  Nov 07, 2013 1:34:29 PM org.apache.fop.events.LoggingEventListener processEvent
  Information: Rendered page #1.
  Nov 07, 2013 1:34:29 PM org.apache.fop.events.LoggingEventListener processEvent
  Warnung: Content overflows the viewport of the fo:region-before on page 2 in block-progression direction by 2989 millipoints. (See position 59:-1)
  Nov 07, 2013 1:34:29 PM org.apache.fop.events.LoggingEventListener processEvent
  Information: Rendered page #2.
  </code></pre>
  
  <p>Dont mind the URLs.</p>