在FOP中使用OutputStream渲染图像 [英] Render image using OutputStream In FOP
问题描述
我想在FOP生成的PDF上渲染图像.要渲染图像,我正在使用标签<fo:external-graphic>
,如下所示:
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
,则使用相同的代码PDF可以成功生成PDF,但是如果我在Glassfish
上部署应用程序,则会出错./strong>
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屋!