hem Posted February 27, 2007 Share Posted February 27, 2007 I put an JRBeanCollectionDatasource in a jasperreport. The Bean contains a BufferedImage. this image is placed on the report.When I show the Report with Jasperviewer the Image is Ok, but when the report is exported to Pdf the image becomes black.I also tried to export the report to HTML, but then the image becomes blurry. I exported the report with: JasperExportManager.exportReportToPdfFile(jasperPrint, "/test.pdf"); Please help. Martijn Link to comment Share on other sites More sharing options...
tracbt Posted February 28, 2007 Share Posted February 28, 2007 We're having this same problem (only on Macintosh?) Link to comment Share on other sites More sharing options...
hem Posted March 6, 2007 Author Share Posted March 6, 2007 I'm using linux. I don't know how to solve this problem. Link to comment Share on other sites More sharing options...
slaisne Posted March 6, 2007 Share Posted March 6, 2007 I'm using JasperReports on Macintosh since long time, but I've not problem to display image and export to pdf.May you tell me more about how you displays the BufferImage.Do you use JRImageRenderer? Link to comment Share on other sites More sharing options...
hem Posted March 8, 2007 Author Share Posted March 8, 2007 The bufferedimage is created from a graphics2D.The image is placed in a JRBeanCollectionDatasourceas an Object.This field is placed on the report as an image.(java.awt.Image)$F{grafiek} Do I have to convert this image to a JRImageRenderer?and how do I do that? Still it's strange that the image appears correct inJasperviewer and not in the pdf.It seams like the pdfconvertor does't work as it should. Link to comment Share on other sites More sharing options...
hem Posted April 3, 2007 Author Share Posted April 3, 2007 I found the problem. The Bufferedimage was created by:BufferedImage image = new BufferedImage(X, Y, BufferedImage.TYPE_INT_ARGB); I changed it to:BufferedImage image = new BufferedImage(X, Y, BufferedImage.TYPE_INT_RGB); Now the image appears in the created pdf file. I'm curious why it doesn't work with the first option, so if someone knows the reason, please let me know. :cheer: Link to comment Share on other sites More sharing options...
hem Posted April 3, 2007 Author Share Posted April 3, 2007 the emoticons messed up my reply: TYPE_INT_ARGB was changed intoTYPE_INT_RGB problem solved.... Link to comment Share on other sites More sharing options...
teodord Posted April 3, 2007 Share Posted April 3, 2007 Hi, What version of JasperReports are you using and on what version of JDK? Thanks,Teodor Link to comment Share on other sites More sharing options...
hem Posted April 3, 2007 Author Share Posted April 3, 2007 Jasperreport 1.3.0Java 1.6on Linux and windows 2000 Link to comment Share on other sites More sharing options...
christiaan_se Posted May 1, 2007 Share Posted May 1, 2007 We actually encountered the same problem when moving to 1.3.2 (jdk 6 u1, XP) Is the provided solution the way to go, or does this need to be fixed in Jasperreports? kind regards,Christiaan Link to comment Share on other sites More sharing options...
teodord Posted May 2, 2007 Share Posted May 2, 2007 Hi, In JasperReports 1.3.0 we introduced some modifications to better deal with image loading and encoding as well as transparent images.If you experience problems with images that used to work when upgrading to a more recent JR version, then we need to know what kind of images are they and how you create them, because they probably worked before due to something that we did wrong in JR and now that we no longer do it, they no longer work as they used to. Thank you,Teodor Link to comment Share on other sites More sharing options...
christiaan_se Posted May 3, 2007 Share Posted May 3, 2007 Hi Teodor,we replaced our BufferedImage.TYPE_INT_ARGB code with ImageIO.read(imageFile) which already gave better transparency results in previewing the report. When exporting to pdf, the results are different (less good) as the 1.2.6 version. I've attached the pdf documents and the images used. We actually always convert the images to png before displaying them (could be another format if you think that is more appropriate). So what we basically do:- load the image with: BufferedImage bufImage = ImageIO.read(imageFile);- store the image as bytearray in png format:ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);ImageIO.write(image, PICTURE_FORMAT, baos);- load the image bytes into BufferedImage again and provide it as a parameter to report:BufferedImage im = ImageIO.read(new ByteArrayInputStream(imagebytes)); kind regards,Christiaan Link to comment Share on other sites More sharing options...
christiaan_se Posted May 3, 2007 Share Posted May 3, 2007 2nd attempt adding files [file name=Images_jasper_1.zip size=162589]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/Images_jasper_1.zip[/file] Link to comment Share on other sites More sharing options...
christiaan_se Posted May 3, 2007 Share Posted May 3, 2007 The images.... [file name=images.zip size=159542]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/images.zip[/file] Link to comment Share on other sites More sharing options...
christiaan_se Posted May 3, 2007 Share Posted May 3, 2007 and the pdf with version 1.3.3 (nice work on the size reduction btw;) Also, we are using the itext 2.0.2 [file name=Images_jasper_1.pdf size=99732]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/Images_jasper_1.pdf[/file] Link to comment Share on other sites More sharing options...
teodord Posted May 3, 2007 Share Posted May 3, 2007 Hi, You should not give JasperReports the image as a java.awt.Image instance (or BufferedImage as you say).If you do so, information about the type of the image is lost and JR would try to encode it as a JPG.Your images have transparency information in them, because they are PNGs and when embedded as JPGs in PDF, this is how they look. You should simply pass the image file name to JasperReports and let it load the image. It will be able to detect it is a PNG and transparency information will be preserved. But if you still think you need to pass them to JasperReports as Image objects (maybe you do some image processing with them), then in the <imageExpression> in JasperReports, wrap the Image object into a JRRenderable instance by calling JRImageRenderer.getInstance(yourImage, JRRenderable.IMAGE_TYPE_PNG, JRImage.ON_ERROR_TYPE_ERROR) This way JR will know it is a PNG and will use the appropriate image encoder, and not the default JPG one. I hope this helps.Teodor Link to comment Share on other sites More sharing options...
christiaan_se Posted May 3, 2007 Share Posted May 3, 2007 Thanks, looks great now. Link to comment Share on other sites More sharing options...
naeemahmad Posted January 27, 2009 Share Posted January 27, 2009 Hi Teodord, I am using jasperreports 3.0.0 with java 1.6. I am facing the same problem of black image when exporting to pdf. I have tried to wrap my image object into JRRenderable instance but the results are same. Actually i am creating JfreeChart and creating image through this chart, then i send this image towards jasper to display it into reports. So according to Product requirements i cant save this image and send string path to jasper. Please give any idea regarding this matter. Thank you NA Link to comment Share on other sites More sharing options...
nnvc Posted October 8, 2009 Share Posted October 8, 2009 Hi!I have the same problem but with chart. I am creating a dynamic chart with jrDesignChart. When I execute it´s ok i can see the chart, but when i print it, I get a black square.Thanks in advance Link to comment Share on other sites More sharing options...
mdselimamr Posted December 14, 2023 Share Posted December 14, 2023 I have faced the issue. and I took a screenshot of the image and saved it as another jpg file. then it was working properly. 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