Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jasper Report- JRException: Image read failed

 
Prabhat Kumar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

I am facing a problem in loading of images in PDF using JasperReport(itext2.1.3). I have created a jasperreport page which print in specified no of pages as per user choice with same content. In the page, images are used which is set as InputStream as jasper report field.
If report is getting prepared for one page, then image gets loaded properly and there does not have any problem with PDF preparation but in case of multiple pages, below exception gets raised:

net.sf.jasperreports.engine.JRException: Image read failed.
at net.sf.jasperreports.engine.util.JRJdk14ImageReader.readImage(JRJdk14ImageReader.java:77)
at net.sf.jasperreports.engine.util.JRImageLoader.loadImage(JRImageLoader.java:248)
at net.sf.jasperreports.engine.JRImageRenderer.getImage(JRImageRenderer.java:354)
at net.sf.jasperreports.engine.JRImageRenderer.getOnErrorRendererForImage(JRImageRenderer.java:307)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportImage(JRPdfExporter.java:1160)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportElements(JRPdfExporter.java:675)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportPage(JRPdfExporter.java:641)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportReportToStream(JRPdfExporter.java:536)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:323)

Plese help to solve this problem.

Thanking you in advance,
Prabhat Kumar
 
visitor visitor
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have probably IntutStream not ok,
Try to test it before you add it to Jasper Report parameters map

import java.awt.Image;
import javax.imageio.ImageIO;

private boolean isReportImageOK(InputStream logoFile) //throws Exception
{
boolean isImageOk = false;

Image image = null;
try
{
image = ImageIO.read(logoFile);
logoFile.reset();
}
catch (IOException e)
{
logger.error("IO exception ");
//throw new Exception(e);
}

if (image == null)
{
logger.error("Image incorrect ");
}
else
{
logger.error("Image correct ");
isImageOk = true;
}

return isImageOk;
}


if result will be "false" then you can switch to another Image.

Best regards,
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
visitor visitor, please see your PM for an important Administrative message.
 
qiongchun chen
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I fixed this error by setting the image control's property "on error type" to "Blank".
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to Javaranch qiongchun chen!
 
David Barrera
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I solved this problem setting true on using cache property



Prabhat Kumar wrote:Dear All,

I am facing a problem in loading of images in PDF using JasperReport(itext2.1.3). I have created a jasperreport page which print in specified no of pages as per user choice with same content. In the page, images are used which is set as InputStream as jasper report field.
If report is getting prepared for one page, then image gets loaded properly and there does not have any problem with PDF preparation but in case of multiple pages, below exception gets raised:

net.sf.jasperreports.engine.JRException: Image read failed.
at net.sf.jasperreports.engine.util.JRJdk14ImageReader.readImage(JRJdk14ImageReader.java:77)
at net.sf.jasperreports.engine.util.JRImageLoader.loadImage(JRImageLoader.java:248)
at net.sf.jasperreports.engine.JRImageRenderer.getImage(JRImageRenderer.java:354)
at net.sf.jasperreports.engine.JRImageRenderer.getOnErrorRendererForImage(JRImageRenderer.java:307)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportImage(JRPdfExporter.java:1160)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportElements(JRPdfExporter.java:675)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportPage(JRPdfExporter.java:641)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportReportToStream(JRPdfExporter.java:536)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:323)

Plese help to solve this problem.

Thanking you in advance,
Prabhat Kumar
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic