Question

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 alfresco 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: fopconfig:

<fop version="0.94">
 <base>./</base>
 <font-base>./</font-base>
 <renderer mime="application/postscript">
 <fonts>
        <font kerning="yes" embed-url="/fonts/arial.ttf" encoding-mode="auto">
            <font-triplet name="Arial" style="normal" weight="normal" />
        </font>
    </fonts>
   </renderer>
</fop>

Created a class file as follows:

import java.io.InputStream;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.URIResolver;
import javax.xml.transform.stream.StreamSource;

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 here is part of my code for FOPTranformer:

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

Solution

I think you need to load the font-configuration when you create the FopFactory, see http://xmlgraphics.apache.org/fop/1.0/embedding.html#config-external

However FOP will use the Arial font by default if you specify "sans-serf" as font-family in the XSL-FO file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top