I’m creating a report using foundsets from Servoy, but I have a problem with images… Well, the images aren’t showed in the report…
I had tried it showing the image as several field class in iReports, but I didn’t get nothing…
Anybody knows what field class I need to show the images? Anybody can help me with this? (Perhaps I must to post it in jasperreports site issues…)
Thanks in advance!!!
Best regards,
Gerardo.
P.S.: by now, I need only an image in report header (the company logo in a invoice), due to this, I have a tricky workaround: I’m creating a temp file and I’m showing that file in report from full path to that temp file…
// ...
// Creates a temp file (using Servoy file plugin) with logo (media data) from my companies table
// and returns full path to that file:
var pd_logo = getImagePath(_to_empresas_saas_company.logo);
// ...
// attach the full path to params object:
params.p_logotipo = pd_logo;
// ...
// just call jasper reports plugin:
plugins.jasperPluginRMI.runReport(foundset, reportName, false, 'view', params);
We store static images in Servoy’s web server: “/Applications/Servoy/application_server/server/webapps/ROOT/image_directory”. You can reference these images using an image expression in Jasper that specifies the URL to the image (ie: (String) “http://localhost:8080/image_directory/image_name.jpg”).
You can abstract this a bit so that the server URL is not hard coded into the report:
1- create a string parameter (“serverURL” in this example) with a default expression of “http://localhost:8080”
2- change the image expression to include the server URL parameter: "$P{serverURL} + “/image_directory/image_name.jpg”
3- pass the server URL to the report when calling from Servoy
This will show your images from within iReport while developing and from Servoy when deployed.
But in my case, the image is not static, I’m loading the company logo from a table of companies data (in the solution, with a Saas enviroment, an admin user can select and load a logo for his company in a form with his companies data). That way, creating the temp file with the database data, I can show that logo with the full path (my strategy in this point looks like yours).
With this workaround I can solve the logo image (it’s only one image for each invoice), but if I want to generate a report with a list of products or employees cards, that strategy does’t look very proper… (creating a temp file for the image of each employee or product is not a very interesting strategy, don’t you think?)
For dynamic images, you can use the InputStream type. Steps:
1- create your report query, containing the byte or other blob fields. click “read the fields” so jasper knows what fields are in the query.
2- now in the library, right-click a blob field and select “edit”. change the field class type to “java.io.InputStream”.
3- now place an image on your report (not a field!). select its properties and change the image expression class to “java.io.InputStream”
4- still in the image properties, enter the blob field in the image expression without quotes (ie: $F{blob_name}, not “$F{blob_name}”)
Building on Jason’s method (thanks for the awt code!), you can send an image as a parameter as well. For graphics that don’t differentiate based on record row – such as your header graphic case – this would be appropriate.
1- create a parameter in jasper of type “java.awt.Image” (called “header_graphic” in this example)
2- place an image on your report. select its properties and change the image expression class to “java.awt.Image”
3. still in the image properties, enter the parameter name in the image expression without quotes (ie: $P{header_graphic})
4. send a java.awt.Image over from the Servoy method calling the report. how you find the record with the correct image i have left out:
var image = new Packages.java.io.ByteArrayInputStream(insert_record_blob_field_here)
var image_awt = Packages.javax.imageio.ImageIO.read(image)
plugins.jasperPluginRMI.runReport(controller.getServerName(),'image_test.jrxml',null,'view',{header_graphic: image_awt})
I agree, but it would be (very) nice if the google servoy-jasper-group messages are automatically pushed to a (read only) Jasper section on the Servoy forum…
That way I don’t have to monitor both sites…
I use the rss feed of the servoy forum by the hour and I am very pleased with it !
Another advantage of having a separate section here: way more people will see the information. Including all new Servoy developers coming online who may have no idea about the jasper plugin to begin with.
I’m agree with posting doubts and solutions about jasperReports plugin/Servoy in the both sites… Perhaps lwjwillemsen’s idea it’s a good tip for do it…
Hi all,
I am little new to servoy, I want to display photo on jasper report(report runs dynamically), photos are placed on the server, when the report is run from (after downloading from the server on different m/c ) smart client, the report appears but the photo is missing so is there any way to display photo / image on the jasper report. How can I display photos on ireport?
It will be great if any one can provide me solution as soon as possible.
chourasia.sheetal02:
Hi all,
I am little new to servoy, I want to display photo on jasper report(report runs dynamically), photos are placed on the server, when the report is run from (after downloading from the server on different m/c ) smart client, the report appears but the photo is missing so is there any way to display photo / image on the jasper report. How can I display photos on ireport?
It will be great if any one can provide me solution as soon as possible.
Sheetal
Hi Sheetal,
Try using the extraDirs property of the Servoy JasperReports plugin, along with the plugin’s com.servoy.plugins.jasperreports.JasperReportsResourceLoader.loadImage(…) method in the imageExpression (also the imageExpression class should be “java.awt.Image” in the report), if you want to use Servoy + the jasper plugin.
But the com.servoy.plugins.jasperreports.JasperReportsResourceLoader.loadImage function should also work for a report launched from iReport.
Also check some older release notes (already suggested by Tom above) or the plugin site’s forum too for info related to the plugin, jasperreports and image loading.