简体   繁体   English

FopFactory缺少方法

[英]FopFactory missing methods

Recently I faced problem with PDF generation that some glyphs was represented with '#'. 最近,我遇到了PDF生成问题,即某些字形用'#'表示。 I made my own fop config file and tried this: 我制作了自己的FOP配置文件并尝试了以下操作:

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

But it seems like fopFactory doesn't have method setUserConfig . 但似乎fopFactory没有方法setUserConfig

Also I tried this: 我也试过这个:

fopFactory.getFontManager().setFontBaseURL(fontBase);

But result is the same - FontManager doesn't have method setFontBaseURL . 但是结果是相同的FontManager没有方法setFontBaseURL

My maven dependency is: 我的Maven依赖项是:

<dependency>
    <groupId>org.apache.xmlgraphics</groupId>
    <artifactId>fop</artifactId>
    <version>2.1</version>
</dependency>

Tried to add jar manually but that didn't change the thing. 试图手动添加jar,但这并没有改变事情。

Found here how to use user configs but the struggle is that I need to use xsl template in constructor newInstance() . 这里找到如何使用用户配置的方法,但困难是我需要在构造函数newInstance()使用xsl模板。 How is it possible to set both xsl (note: NOT XSL-FO!) and config? 如何同时设置xsl(注意:NOT XSL-FO!)和config?

Here is my code fragment: 这是我的代码片段:

    // setup xml input source
    String xml = object.toXml();
    StreamSource xmlSource = new StreamSource(new ByteArrayInputStream(xml.getBytes("UTF-8")));

    // setup xsl stylesheet source
    File xslFile = new File(stylesheetPath);
    FileInputStream xslFileStream = new FileInputStream(xslFile);
    StreamSource xslSource = new StreamSource(xslFileStream);

    // get transformer
    TransformerFactory tfactory = TransformerFactory.newInstance();
    Transformer transformer = tfactory.newTransformer(xslSource);

    // setup FOP
    FopFactory fopFactory = FopFactory.newInstance(xslFile);
    FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
    foUserAgent.setProducer(this.getClass().getName());
    Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, pdfContent);

    // perform transformation 
    Result res = new SAXResult(fop.getDefaultHandler());
    transformer.transform(xmlSource, res);

As lfurini pointed out, setFontBaseURL() disappeared in some pre-2.0 version of Apache FOP. 正如lfurini指出的那样, setFontBaseURL()在Apache FOP的2.0之前的版本中消失了。 Most programmatic configuration is now done using FopFactoryBuilder . 现在,大多数程序化配置都是使用FopFactoryBuilder完成的。 Also see Apache's guide to upgrading to FOP 2.1 . 另请参阅Apache的升级到FOP 2.1的指南

FOPFactoryConfigurator class has been removed, fopFactory.setUserConfig(cfg) is not available anymore. FOPFactoryConfigurator类已被移除, fopFactory.setUserConfig(cfg)不再可用。 This is when you use newer than (1.x or earlier version of fop) 这是当您使用比(1.x或更早版本的fop)更高的版本时

check this https://xmlgraphics.apache.org/fop/2.1/upgrading.html 检查此https://xmlgraphics.apache.org/fop/2.1/upgrading.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM