trodino Posted June 17, 2008 Share Posted June 17, 2008 I have a report that prints a signature image (.bmp). Sometimes there is no signature, so I don't want to print anything in the image space. Currently, my applet copies the signature file to a generic file name, or if there is no signature a "blank" (5x5 plain white) image is copied. Problem is whenever I print the blank image, my pdf is corrupted. When I try to open with Acrobat, I get an error message: Wrong operand type, and can't view or print the report. Optimally, what I would like to do is dynamically determine whether I have a signature image, and print it only when I have one. Is that possible? Link to comment Share on other sites More sharing options...
lshannon Posted June 17, 2008 Share Posted June 17, 2008 Does the copying of this file occur before you fill the report? If so, you could write a helper class with a static method call printSignature() that checks this image file to see if it is the blank image (I am not a image expert when it comes to Java programming so I am not totally sure how this could be done). If it is the blank this method would return a false. Then in your report design you could add a PrintWhenCondition to the image element for the signature that is simply a call to the helper. It will then only print the element in the report when it is not the blank. This might do the trick. Let me know if you have any questions. Link to comment Share on other sites More sharing options...
trodino Posted June 17, 2008 Author Share Posted June 17, 2008 That makes good sense. I can handle the java side of that, but not sure how to go about the report side.... Link to comment Share on other sites More sharing options...
trodino Posted June 17, 2008 Author Share Posted June 17, 2008 That makes good sense. I can handle the java side of that, but not sure how to go about the report side.... Link to comment Share on other sites More sharing options...
lshannon Posted June 17, 2008 Share Posted June 17, 2008 Ok, so what you need to do on the report side are 3 things. 1. Package up your helper class in a Jar, ensure the method that checks the image is static and returns a Boolean object (not boolean primative). 2. Ensure the jar from step one is in the classpath (for iReport you can just put it in the lib directory, make sure to restart iReport after adding it). 3. On the image element in the report (I am assuming you are working in iReport), right click on it and select Properties -> Common. In the print when expression put something like this: com.mypackage.HelperClass.printSignature() You can add a import to your report in iReport by going to Edit -> Report Import Directives. Here you can add com.mypackage.* which will allow you to reference HelperClass without the full path name. Hope this makes things more clear. Link to comment Share on other sites More sharing options...
trodino Posted June 18, 2008 Author Share Posted June 18, 2008 Thanks! Your solution got me going in the right direction. Once I started to implement it, though, I realized that since I know whether I have a signature before I run the report, I can just set a report parameter to Y or N to indicate I have a signature, and just check the parameter in the print when expression. It's not the elegant, dynamic solution I was thinking of, but it works just fine. Link to comment Share on other sites More sharing options...
lshannon Posted June 18, 2008 Share Posted June 18, 2008 Great! That sounds like a pretty good solution to me, simpler than what I was suggesting. Link to comment Share on other sites More sharing options...
trodino Posted June 18, 2008 Author Share Posted June 18, 2008 Well... It works just fine if you don't try to auto-print it. I get an error auto-printing the report: net.sf.jasperreports.engine.JRException: Image Read Failed. See attached for the stack trace. Here's what my java code does: JRXmlDataSource rptData=new JRXmlDataSource(dataFile); JasperPrint jasperPrint=JasperFillManager.fillReport(rptTemplate, rptParams, rptData.dataSource()); JasperExportManager.exportReportToPdfFile(jasperPrint, rptName); JasperPrintManager.printReport(jasperPrint, false); I noticed that my pdf has a signature and my printout doesn't, so I checked the signature element in the report and see it's set to Blank on Error. I changed it to Error on Error and sure enough, there's a problem. Not really sure why I can get a pdf but not a printout. [file name=JRException.txt size=2050] Link to comment Share on other sites More sharing options...
trodino Posted June 19, 2008 Author Share Posted June 19, 2008 OK, it looks like this error is caused by a bad bmp image. When no signature is given in the main app, the process sends a 0x0 size bmp to my applet, which seems to blow up most up the editors I have available on my desktop, and I assume is also the problem with jasper. Another contributing factor is probably Java version. Of course, I have a fairly recent version, but users in the field are running 1.4.2. So I have to build for the older version. 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