0
我正在使用Apache FOP將SVG呈現爲PDF。這個SVG有一個特殊的字體,我也想在結果PDF中使用。Apache FOP嵌入式,如何使用配置文件
我使用的是這樣的一個配置文件:
<?xml version="1.0"?>
<fop version="1.0">
<base>.</base>
<source-resolution>72</source-resolution>
<target-resolution>72</target-resolution>
<default-page-settings height="11.00in" width="8.50in" />
<renderers>
<renderer mime="application/pdf">
<filterList>
<value>flate</value>
</filterList>
<fonts>
<font
metrics-url="path/to/metrics.xml"
kerning="yes"
embed-url="path/to/font.ttf">
<font-triplet name="font name" style="normal" weight="normal" />
</font>
</fonts>
</renderer>
</renderers>
</fop>
我複製並從示例配置粘貼,並編輯了我並不需要所有的渲染器。 現在我想要使用的配置是這樣的:
public void convertSVG2PDF(String svg, OutputStream out) throws IOException, TranscoderException {
// Create transcoder
AbstractFOPTranscoder transcoder = new PDFTranscoder();
DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
Configuration cfg;
try {
File configFile = new File("path/to/config.xml");
cfg = cfgBuilder.buildFromFile(configFile);
transcoder.configure(cfg);
System.err.println(cfg.getValue());
} catch (Exception e) {
System.err.println(e.getMessage());
}
// Setup input
Reader in = new java.io.StringReader(svg);
try {
TranscoderInput input = new TranscoderInput(in);
// Setup output
try {
TranscoderOutput output = new TranscoderOutput(out);
// Do the transformation
transcoder.transcode(input, output);
} finally {
out.close();
}
} finally {
in.close();
}
}
這使得一個完全正常的PDF,但不使用的字體。 當我嘗試cfg.getValue(I也得到這樣的信息)
No值與所述配置元件 「FOP」 在文件相關聯:/path/to/conf.xml:1:20
我也嘗試將配置重命名爲.xconf,但這並沒有改變任何東西。