Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ApacheFOP嵌入式,如何使用配置文件_Apache_Pdf_Svg_Apache Fop - Fatal编程技术网

ApacheFOP嵌入式,如何使用配置文件

ApacheFOP嵌入式,如何使用配置文件,apache,pdf,svg,apache-fop,Apache,Pdf,Svg,Apache Fop,我正在使用ApacheFop将SVG呈现为PDF。这个SVG有一种特殊的字体,我想在生成的PDF中也使用这种字体 我使用的配置文件如下所示: <?xml version="1.0"?> <fop version="1.0"> <base>.</base> <source-resolution>72</source-resolution> <target-resolution>72</

我正在使用ApacheFop将SVG呈现为PDF。这个SVG有一种特殊的字体,我想在生成的PDF中也使用这种字体

我使用的配置文件如下所示:

<?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()时也会收到此消息

文件:/path/to/conf.xml:1:20中没有与配置元素“fop”关联的值


我还尝试将配置重命名为.xconf,但这没有改变任何东西。

试试这个……它对我有用:

FopFactory fopFactory;
fopFactory = FopFactory.newInstance();



File configFile = new File("path/to/config.xml");
fopFactory.setUserConfig(configFile);

这适用于FOP2.3版本

File xconf = new File(this.fopConfigFile.toURI()); 
FopConfParser parser = null;
try {
  //parsing configuration 
  parser = new FopConfParser(xconf);
} catch (SAXException e) {
    throw new UncheckedIOException(new IOException(e));
} catch (IOException e) {
    throw new UncheckedIOException(e);
}  
//building the factory with the user options
FopFactoryBuilder builder = parser.getFopFactoryBuilder(); 
this.fopFactory = builder.build();
Fop fop = this.fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
文件: