I have an issue configuring Batik PDFTranscoder for Svg to Pdf conversion. I want to embed custom truetype fonts to PDF output, therefore I utilize Batik transcoder. I supply font configuration in fop config file, as described here: https://xmlgraphics.apache.org/fop/2.2/fonts.html
I tried conversion with org.apache.xmlgraphics.Fop versions 2.1 and 2.2. Without any success.
My pdf output, comes with 'Times New Roman' font instead of coming with embedded font 'Arial', as it should, based on example below:
My config file:
<?xml version="1.0" encoding="UTF-8"?>
<fop version="1.0">
<renderers>
<renderer mime="application/pdf">
<fonts>
<directory>C:/path/to/fontsfolder</directory>
<auto-detect/>
</fonts>
</renderer>
</renderers>
</fop>
Here's my transcoder code:
import org.apache.batik.transcoder.*;
import org.apache.fop.svg.PDFTranscoder;
import org.w3c.dom.Document;
PDFTranscoder transcoder = new PDFTranscoder();
try {
DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
Configuration cfg = cfgBuilder.buildFromFile(new File("path-to-xml-config-file"));
ContainerUtil.configure(transcoder, cfg);
} catch (Exception e) {
throw new TranscoderException(e);
}
transcoder.transcode(new TranscoderInput(doc),
new TranscoderOutput(os));
Sample svg file:
<defs>
<style type="text/css">
@font-face{font-family:'Arial';font-style: normal;font-weight:
400;src:url('C:/path/to/fontsfolder/arial.ttf')
format('truetype');}
</style>
</defs>
<text x="55" y="245" style="font-family: 'Arial'; font-weight:normal;
font-style: normal" >Sample text</text>
Can anyone tell me what I am missing here with Transcoder configuration? Embedding svg fonts into svg file is not an option in this case.