Some notes on font embedding using FOP's PDF Transcoder.

Here's the Java code to convert an SVG file to a PDF:

        //Create transcoder
        Transcoder transcoder = new PDFTranscoder();

        //Configure the transcoder
        try {
            DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
            Configuration cfg = cfgBuilder.buildFromFile(new File("pdf-renderer-cfg.xml"));
            ContainerUtil.configure(transcoder, cfg);
        } catch (Exception e) {
            throw new TranscoderException(e);
        final int dpi = 300;
                new Float((float)(25.4 / dpi))); 
        transcoder.addTranscodingHint(XMLAbstractTranscoder.KEY_XML_PARSER_VALIDATING, Boolean.FALSE);
        transcoder.addTranscodingHint(PDFTranscoder.KEY_STROKE_TEXT, Boolean.FALSE);

        //Setup input
        InputStream in = new;
        try {
            TranscoderInput input = new TranscoderInput(in);
            //Setup output
            OutputStream out = new;
            //Buffer the OutputStream for better performance
            out = new;
            try {
                TranscoderOutput output = new TranscoderOutput(out);
                //Do the transformation
                transcoder.transcode(input, output);
            } finally {
        } finally {

The pdf-renderer-cfg.xml file referenced in the code looks like this:

<?xml version="1.0" encoding="UTF-8"?>
    <font metrics-url="file:C:/Dev/FOP/temp/fonts/FUTURAL.ttf.xml" kerning="no" embed-url="file:C:/Dev/FOP/Temp/fonts/FUTURAL.ttf">
      <font-triplet name="Futura Lt BT" style="normal" weight="normal"/>

The full source code of this example can be downloaded from

To run the example put the fop-transcoder-allinone.jar and batik.jar from FOP's lib directory (from CVS HEAD) where you extract the ZIP file and run doit.bat (on Windows).

Note: If FOP can use the embedded font to paint text depends on a number of variables. Here's a number of reasons why FOP can't paint text as text but will delegate to Batik to paint the text as shapes in which case the font needs to be available from your operating system:

SvgNotes/PdfTranscoderTrueTypeEmbedding (last edited 2009-09-20 23:52:22 by localhost)