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
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
18 Answers:
Posted on March 7, 2007 at 5:39pm
The bufferedimage is created from a graphics2D.
The image is placed in a JRBeanCollectionDatasource
as 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 in
Jasperviewer and not in the pdf.
It seams like the pdfconvertor does't work as it should.
The image is placed in a JRBeanCollectionDatasource
as 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 in
Jasperviewer and not in the pdf.
It seams like the pdfconvertor does't work as it should.
Posted on April 3, 2007 at 9:55am
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:
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:
Posted on May 2, 2007 at 12:45pm
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
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
Posted on May 3, 2007 at 9:30am
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
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
Posted on May 3, 2007 at 9:33am
2nd attempt adding files [file name=Images_jasper_1.zip size=162589]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/Ima...
Posted on May 3, 2007 at 9:35am
The images.... [file name=images.zip size=159542]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/ima...
Posted on May 3, 2007 at 9:36am
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/Ima...
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/Ima...
Posted on May 3, 2007 at 12:47pm
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
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
Posted on January 27, 2009 at 2:19am
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