简体   繁体   中英

FopFactory missing methods

Recently I faced problem with PDF generation that some glyphs was represented with '#'. I made my own fop config file and tried this:

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

But it seems like fopFactory doesn't have method setUserConfig .

Also I tried this:

fopFactory.getFontManager().setFontBaseURL(fontBase);

But result is the same - FontManager doesn't have method setFontBaseURL .

My maven dependency is:

<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.

Found here how to use user configs but the struggle is that I need to use xsl template in constructor newInstance() . How is it possible to set both xsl (note: NOT XSL-FO!) and 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. Most programmatic configuration is now done using FopFactoryBuilder . Also see Apache's guide to upgrading to FOP 2.1 .

FOPFactoryConfigurator class has been removed, fopFactory.setUserConfig(cfg) is not available anymore. This is when you use newer than (1.x or earlier version of fop)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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