在 FOP 中使用 OutputStream 渲染图像 [英] Render image using OutputStream In FOP

查看:26
本文介绍了在 FOP 中使用 OutputStream 渲染图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在将由 FOP 生成的 PDF 上渲染图像.为了渲染图像,我使用标签 如下:

I wanted to render image on PDF which is going to generated by FOP. To render image I am using tag <fo:external-graphic> As below :

<fo:external-graphic src="url('../offlinePaper/displayImage?disImg=4bec89f0-5b97-40c3-b7c9-ac555a664df8')" inline-progression-dimension.maximum="100%"  content-height="scale-down-to-fit" content-width="scale-down-to-fit"> </fo:external-graphic>

我也尝试将完整网址设为:

I also tried by giving full URL as:

<fo:external-graphic src="http://10.2.10.79/Web/offlinePaper/displayImage?disImg=e391d672-ebf4-44d8-86cb-2cf987a50bf7" inline-progression-dimension.maximum="100%"  content-height="scale-down-to-fit" content-width="scale-down-to-fit"> </fo:external-graphic>

在控制器中,我有一个请求映射 (../offlinePaper/displayImage) 它从 getParameter 获取图像名称 disImg 并解密图像并在 OutputStream 中返回.

In controller I am having an request mapping (../offlinePaper/displayImage) which takes image name disImg from getParameter and decrypt the image and return in OutputStream.

但是当我生成 PDF 时,我发现日志文件中的错误为:

But when I generate PDF I found Error in log file as:

Image not available. URI: http://10.2.10.79:80/Web/offlinePaper/displayImage?disImg=4bec89f0-5b97-40c3-b7c9-ac555a664df8. Reason: org.apache.xmlgraphics.image.loader.ImageException: The file format is not supported. No ImagePreloader found for http://10.2.10.79:80/Web/offlinePaper/displayImage?disImg=4bec89f0-5b97-40c3-b7c9-ac555a664df8 (No context info available)

但是,如果我复制此 URL 并粘贴到 URL 中,则图像会显示在浏览器中,而且我还发现,当我生成 PDF 时,不会调用假设调用图像解密的请求映射.

But if I copy this URL and paste in URL then image get shown in browser and I also found that when I generate PDF the request mapping which is suppose to get call for image decryption is not getting called.

更新

还有一个奇怪的想法,我知道如果 Web 服务器是 Tomcat,但如果我在 Glassfish 上部署应用程序,则使用相同的代码可以成功生成 PDF> 出现错误.

Also a strange think I come to know that with same code PDF get successfully generated if web server is Tomcat but if I deploy application on Glassfish it's giving error.

推荐答案

在异常跟踪站:

ImageException: 不支持文件格式

ImageException: The file format is not supported

FO 似乎能够根据文件扩展名找到 ImagePreloader.如果没有找到,它就会中断.

The FO seems to be able to find an ImagePreloader according to file extension. If it doesn't find any, it breaks.

我建议更改 url 的构建方式.应该包含一个真实的图像文件名.

I'd propose to change the way how the url is built. There should be a real image file name included.

所以,而不是:

../offlinePaper/displayImage?disImg=4bec89f0-5b97-40c3-b7c9-ac555a664df8

../offlinePaper/displayImage?disImg=4bec89f0-5b97-40c3-b7c9-ac555a664df8

试试

../offlinePaper/displayImage/disImg4bec89f0-5b97-40c3-b7c9-ac555a664df8.jpg

../offlinePaper/displayImage/disImg4bec89f0-5b97-40c3-b7c9-ac555a664df8.jpg

这篇关于在 FOP 中使用 OutputStream 渲染图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆