gpt4 book ai didi

java - 使用 fop 2.3 版本时找不到 FOP 图像

转载 作者:行者123 更新时间:2023-11-30 06:05:53 30 4
gpt4 key购买 nike

我已将 FOP 版本从 fop 1.1 升级到 fop 2.3 版本,但得到

org.apache.fop.events.LoggingEventListener processEvent Image not found.

以下是为升级而修改的代码片段。使用fop 2.3掌握查看代码

代码:

  TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();

FOUserAgent foUserAgent = fopFactory.newFOUserAgent();

//foUserAgent.setURIResolver( this.getURIResolver() );
transformer.setURIResolver(this.getURIResolver());

Fop fop = null;
Source src = new StreamSource(new ByteArrayInputStream(foDoc));

if (this.getContentType().equals("application/pdf"))
{
fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, os);
}
else if (this.getContentType().equals("application/postscript"))
{
fop = fopFactory.newFop(MimeConstants.MIME_POSTSCRIPT, foUserAgent, os);
}

查看 fop 2.3 的代码

protected static final FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI(), resolver);

XSLT 代码

<fo:external-graphic src = "stylesheets/Anthem_Join_In.bmp"/>

最佳答案

解析器的 API 已更改,并且记录很少。这段代码在 JSF webApp 中适用于我(fop 2.3)。

final ServletContext sc = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();

// Create ServletContext resource Resolver
ResourceResolver resolver = new ResourceResolver() {
@Override
public Resource getResource(URI uri) throws IOException {
return new Resource(sc.getResourceAsStream(uri.toASCIIString()));
}

@Override
public OutputStream getOutputStream(URI uri) throws IOException {
URL url = sc.getResource(uri.toASCIIString());
return url.openConnection().getOutputStream();
}
};

// Buid the factory
FopFactoryBuilder builder = new FopFactoryBuilder(new URI(sc.getContextPath()), resolver);
FopFactory FOP_FACTORY = builder.build();

我的项目中之前的其余代码保持不变。我没有使用 Transformer.setURIResolver(...)

xml fop 代码如下所示:

<fo:external-graphic width="auto" content-width="164pt" height="auto" src="url(/resources/img/main-logo.png)"/>

关于java - 使用 fop 2.3 版本时找不到 FOP 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51356652/

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