Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using new fonts with Apache FOP in Java

I have to internationalize an application, and therefore have to let a user chose a font for a PDF that I will create at runtime. I want to be able to display a list of font choices from the user's system using

GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();

This works fine for getting fonts, but then it seems that I have to jump through some hoops to get that font to play nice with FOP, as outlined here. I can follow all the instructions that they've outlined, except I'm not sure how to get the location of fonts in order to run TTFReader.

  1. Does anyone know how to list the path of each font that java gathers with the getAllFonts() command?
  2. Is it a good idea to embed fonts in PDFs? For instance the Arial Unicode MS TFF file is ~ 30 MB.
  3. Is this the only way to create internationalized pdfs with FOP and XSL?
like image 215
Jon Avatar asked Oct 20 '09 00:10

Jon


1 Answers

There have been major improvements in font configuration with the last release (FOP 0.95), so please just consult the document there for a much easier approach: http://xmlgraphics.apache.org/fop/0.95/fonts.html#basics

The XML font metrics files are no longer necessary.

To your questions:

  1. That's impossible. Java won't give you that information. That's partly why FOP has its own font subsystem.
  2. Yes, it's actually recommended. Please note that FOP supports font subsetting so only the glyphs needed are embedded in the PDF.
  3. Not sure what you mean. With the above information and an upgrade to the latest release should make this simple enough.
like image 143
Jeremias Märki Avatar answered Sep 29 '22 03:09

Jeremias Märki