venujasper Posted May 13, 2009 Share Posted May 13, 2009 Hi , I am using ireport tool in my application.There is a requirement to show the image on report. I have a blob object field in database to store image.I need to show the blob object field as an image in the report. Have any idea? Thanks in advance. Regards,Kitti Link to comment Share on other sites More sharing options...
Giulio Toffoli Posted May 13, 2009 Share Posted May 13, 2009 Depends by the database. Try defining the field as java.io.InputStream and use it as InputStream in the image expression setting the proper expression class to java.io.InputStreamGiulio Link to comment Share on other sites More sharing options...
venujasper Posted May 13, 2009 Author Share Posted May 13, 2009 Thanks for reply, I am using mysql database.I have used java.io.InputStream, it is successfully compiled,but when i am running it ,showing error message as "Error displaying report page see the console for details". I was not able see errors on the console. Can i get any images such as .gif, jpg, jpeg etc. Link to comment Share on other sites More sharing options...
hangman01 Posted May 13, 2009 Share Posted May 13, 2009 You need to edit the field item that contains your blob to also be java.io.InputStream. I have used this method to successfully display blobs without any problems. Post Edited by hangman01 at 05/13/2009 14:03 Link to comment Share on other sites More sharing options...
jmartens Posted May 14, 2009 Share Posted May 14, 2009 Setting your field and image expression to "java.io.InputStream" will work fine for you as long as the blob contains a GIF, JPEG, or PNG (a binary image). However, if you have PDF documents stored in the blob data - which is pretty common these days - then it won't work for you, you will get an Error exporting print...Image read failed. Although the report is produced, there is nothing where the image should appear.What you have to do is continue to read the blob into a java.io.InputStream field, but then create a scriptlet to utilize a java package to convert it from PDF to InputStream. I did this using the Apache PDFBox open-source package. Also, if the PDF is multi-pages, then each page needs to become a separate image - thus you need the image display to actually be an embedded subreport driven off a JRDataSource object containing the list of images. Below is the code from the scriptlet. I hope this helps.JamesCode:public class ImageScriptlet extends JRDefaultScriptlet{ public ImageScriptlet() { } public void afterDetailEval() throws JRScriptletException { String contentType = ( String ) getFieldValue( "CONTENT_TYPE" ); InputStream docStream = ( InputStream ) getFieldValue( "BLOB_DATA" ); if ( null != contentType ) { ImageDataSource ds = null; List images = new ArrayList(); if ( contentType.equalsIgnoreCase( "application/pdf" ) ) { try { PDDocument document = PDDocument.load( docStream ); List pages = document.getDocumentCatalog().getAllPages(); for ( int i = 0; i < pages.size(); i++ ) { PDPage page = ( PDPage ) pages.get( i ); images.add( getInputStream( page ) ); } document.close(); } catch ( IOException e ) { System.out.println( "IOException during afterDetailEval in ImageScriptlet" ); System.out.println( e.getMessage() ); } } else { images.add( docStream ); } ds = new ImageDataSource( images ); setVariableValue( "BLOB_DATA_SOURCE", ds ); } } Link to comment Share on other sites More sharing options...
eturan Posted October 9, 2009 Share Posted October 9, 2009 I had the same problem with Image read failed. error.. I tried using java.awt.Image and it worked. Would that cause further problems ? Eda Link to comment Share on other sites More sharing options...
gilclefes Posted October 9, 2009 Share Posted October 9, 2009 check the solution from here http://gilbertadjin.wordpress.com/2009/07/01/inserting-images-from-database-into-jasper-reports/hope it helps, feel free to send your comment on this blog postPost Edited by gilclefes at 10/09/2009 17:09 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now