gpt4 book ai didi

java - FopFactory 缺少方法

转载 作者:行者123 更新时间:2023-12-01 06:09:41 24 4
gpt4 key购买 nike

最近我在生成 PDF 时遇到问题,某些字形用“#”表示。我制作了自己的 fop 配置文件并尝试了以下操作:

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

但似乎fopFactory没有方法setUserConfig

我也尝试过这个:

fopFactory.getFontManager().setFontBaseURL(fontBase);

但结果是相同的 - FontManager没有方法setFontBaseURL

我的 Maven 依赖项是:

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

尝试手动添加 jar,但这并没有改变事情。

找到here如何使用用户配置,但困难是我需要在构造函数 newInstance() 中使用 xsl 模板。如何同时设置 xsl(注意:不是 XSL-FO!)和配置?

这是我的代码片段:

    // 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);

最佳答案

正如 lfurini 指出的,setFontBaseURL() 在某些 2.0 之前的 Apache FOP 版本中消失了。现在,大多数编程配置都是使用 FopFactoryBuilder 完成的。另请参阅Apache's guide to upgrading to FOP 2.1 .

关于java - FopFactory 缺少方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37291470/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com