AnsweredAssumed Answered

Unable to include Arial font in FOPTransformer

Question asked by yogesh on Apr 20, 2012
Latest reply on Apr 25, 2012 by billerby
I am working on an application which has some forms and then using FOP it creates pdf files. PDF files that are getting generated are in Time New Roman but I want them in Arial font. I added arial.ttf in projectName->fonts->arial.ttf as described here:

This ttf and code has to go into a amp file but right now I havent added it as jar file for arial.ttf because I am not sure how to make a jar file with just .ttf file,  Here is what I did to accomplish this but pdf are still in times new roman:

<fop version="0.94">

  <!– Base URL for resolving relative URLs –>

  <!– Font Base URL for resolving relative font URLs –>
  <renderer mime="application/postscript">
            <font kerning="yes" embed-url="/fonts/arial.ttf" encoding-mode="auto">
                <font-triplet name="Arial" style="normal" weight="normal" />

Created a class file as follows:

import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.URIResolver;

public class ClasspathUriResolver implements URIResolver

  public Source resolve(String href, String base) throws TransformerException
    Source source = null;
    InputStream inputStream = ClassLoader.getSystemResourceAsStream(href);
    if (inputStream != null)
      source = new StreamSource(inputStream);
    return source;

And then in FOPTransformer i used it like this:

FopFactory fopFactory = FopFactory.newInstance();
         FOURIResolver uriResolver = (FOURIResolver)fopFactory.getURIResolver();
         uriResolver.setCustomURIResolver(new ClasspathUriResolver());
         FOUserAgent foUserAgent = fopFactory.newFOUserAgent();