Jasper report Header static Image and detail images

Playing around with Jasper report studio. I’m stuck with an issue. At the header band, I have an Image (Logo image). Testing the report directly from Jasper studio the image is printed, but once I export the jrxml file and set it as a template for Cuba report, an error is thrown saying the bitmap can’t be found. At Jasper studio, I set the image source from the workspace, but can’t figure out how to export this image together with the jrxml file. When I delete this image from the template at Jasper studio, the jrxml works from cuba.

Any help?


Look at:

bitmap - transforms the given byte array into ByteArrayInputStream and can be used for embedding images into the report. For example:

<field name="Main.image" class="java.lang.Object"/> //image from DB as byte array


Why not create a jasper report parameter then pass the image to the report.

Thanks for your replies.

This leads me to a 2 new questions.

The Static image is at fileStorage. Should I create then at Report designer, the Band info as groovy type dataset and create a map with the bitmap string?

The report is an Invoice and each product has his own Image to be printed. This Image is a FileDescriptor associated to Product Entity and stored in fileStorage, too. Should I change dataset type from JPQL to Groovy to be able to include each Image together with Invoice Line info?

… sorry, but I’m feeling really lost at this point.

My problems are:

  1. Lack of knowlede about groovy
  2. I can’t get how-where-when to pass as parameter an Image (For title band and for detail band)

I will try to explain my case:

I have a report

Using as dataset for detail band a SQL sentence which returns field from diferent entities…
Now, I need to add for each detail record an Image to be printed together. This image is a fileDescriptor field in Product entity.

I think I’ve understood how to setup Jasper template to reference an image passed by parameter, but I have no clue HOW to pass this parameter to the Template from the Cuba report designer.
Taking in count the SQL sentence (above in picture) references fields from different entities,
¿How can I add the Producto Image to each record as a byteArray?
I’m stretching my mind and I think I should use Groovy ¿is this right?
¿Could you give some aproach to do that, please? Sorry for my ignorance.

Eureka!.. took me tons of hours, but finally I got it.
Jasper template has a reference of imageProducto as field and as Image in detail band

<field name="imageProducto" class="java.lang.Object"/> 
<reportElement x="0" y="0" width="34" height="34" uuid="2e553ec0-45cf-43d6-b41d-4df655952230"/>

Then, at Cuba report designer, I define detailband dataset as groovy:

def result = []
def fileStorageService = com.haulmont.cuba.core.global.AppBeans.get('cuba_FileStorageService') 
transactional { em ->
    def query = em.createQuery('select e from database$OrderDetails e where e.order.id=?1')
    query.setParameter(1, params['order'])
    query.resultList.each { d ->
        def referenciaProducto=''
        def imageProducto=null
        if (d.producto!=null) { //if detail line has a product
           def producto = dataManager.reload(d.producto, "productos-view")
           if (producto.image!=null) { //if product has an Image
               imageProducto= fileStorageService.loadFile(producto.image);

        result.add(['referenciaProducto': referenciaProducto, 'imageProducto' : imageProducto], 'conceptoProducto': d.concepto, 'cantifdadProducto': d.cantidad, 'precioProdcuto' : d.baseImponible, 'ivaProducto' : d.impuestoPorcentual, 'descuentoProducto' : d.descuento, 'importeProducto' : d.totalLinea, 'descripcionProducto' : d.observaciones)
return result

… and each product image is printed in every order lines. VOILA!

1 Like