BLOB图像未显示在jasper报告pdf中 [英] BLOB image not displayed in jasper report pdf

查看:154
本文介绍了BLOB图像未显示在jasper报告pdf中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将我的oracle数据库中的图像保存为BLOB。我的模型类包含byte []图像;对应于数据库中的BLOB feild。我必须将数据库中的所有图像导出为PDF。在java中我使用了以下代码:

I have saved image in my oracle data base as BLOB. My model class contains byte[] image; corresponding to the BLOB feild in database.I have to export all the images in data base to PDF. In java i used the following code:




    JasperReport jasperReport = JasperCompileManager.compileReport('jrxml file');
       JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(imageObjList);  
       //imageObjList containing the model 'ImageObj' which contain  byte[] image 
       JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,jasperParameter,ds);
       JasperExportManager.exportReportToPdfStream(jasperPrint,responce.getOutputStream() );

我用iReport创建jrxml文件

I used iReport for creating jrxml file

在我的jrxml中,我创建一个字段作为图像,字段类型为java.io.InputStream

In my jrxml i create a field as image with field class type as java.io.InputStream

在我的图像中我将图像表达式设为$ F {image}并且还将Image Class表达式赋予java.awt.Image。

and in my Image i give Image Expression as $F{image} and also have given Image Class expression as java.awt.Image.

我无法制作我的pdf报告。

I am not able to make my pdf report .

我收到异常




    net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression: 
       Source text : $F{image}
       ..... 
       Caused by: java.lang.ClassCastException: [B cannot be cast to java.io.InputStream
       at ImageReport_1374240048064_891215.evaluate(ImageReport_1374240048064_891215:171)

我需要pdf中的图像。

I need the images in pdf.

推荐答案

错误消息[B不能转换为java.io.InputStream表示字节数组([B]不能是强制转换为InputStream。问题是你的jrxml文件中的图像字段的类型与你的ImageObj bean中的字段类型不匹配。

The error message "[B cannot be cast to java.io.InputStream" means that a byte-array ([B) can not be cast to InputStream. The problem is that the type of the image field in your jrxml file does not match the type of the field in your ImageObj bean.

根据JasperReports Ultimate Guide你可以使用以下类型作为图像表达式的输入数据:

According to the JasperReports Ultimate Guide you can use the following types as input data for an image expression:


  • java.lang.String

  • java.io.File

  • java.net.URL

  • java.io.InputStream

  • java。 awt.Image

  • net.sf.jasperreports.engine.JRRenderable

  • java.lang.String
  • java.io.File
  • java.net.URL
  • java.io.InputStream
  • java.awt.Image
  • net.sf.jasperreports.engine.JRRenderable

所以你会有将byte []转换为另一种数据类型。 InputStream是最简单的方法:

So you will have to convert your byte[] to another datatype. InputStream is the easiest way to go:

将ImageObj中的getter更改为:

Change the getter in ImageObj to:

public InputStream getImage() {
    return new ByteArrayInputStream(image);
}

并将图像类表达式设置为java.io.InputStream。

and set the image class expression to java.io.InputStream.

这篇关于BLOB图像未显示在jasper报告pdf中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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