I am developing an application in Java Swing . I am using JasperReports and iReport in my application.
I have successfully made the connection between JasperReports and database and also loaded the jrxml file.
My Question is that after completing the development of my application I want that applications's users be able to set their logo, can change their header and footers. One way i can do this is by creating a User Interface that is a JFrame which has uploading image option + change the headers and footers of the report. But how do I connect my JFrame components with a JR report so that changes made in components of my JFrame should get reflected in report?
I'm assuming that the meaning of "upload" is saving the image in the hard disk of server computer in a specific path then saving this path in the database.
Convert the uploaded image into InputStream
String imgPath = "[path_of_uploaded_image_here]"; BufferedImage image = ImageIO.read(new File(imgPath)); ByteArrayOutputStream os = new ByteArrayOutputStream(); ImageIO.write(image, "gif", os); InputStream is = new ByteArrayInputStream(os.toByteArray());
Pass the converted image as a parameter to the jasperreport.(here the param name is ENTITY_IMAGE)
Inside the iReport, create a parameter. Data type of this parameter should be java.io.InputStream
Drag an image. Go the image properties. Under the image properties, change the value of Expression Class as java.io.InputStream
then the Image Expression as $P{ENTITY_IMAGE}.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.