HOW-TO Use images in columns

This new feature enables DynamicJasper to use images in the detail band.

In the following example, we are adding an image column (the last one)

FastReportBuilder drb = new FastReportBuilder();
drb.addColumn("State", "state", String.class.getName(),30)
        .addColumn("Branch", "branch", String.class.getName(),30)
        .addColumn("Product Line", "productLine", String.class.getName(),50)
        .addColumn("Item", "item", String.class.getName(),50)
        .addColumn("Item Code", "id", Long.class.getName(),30,true)
        .addColumn("Quantity", "quantity", Long.class.getName(),60,true)
        .addColumn("Amount", "amount", Float.class.getName(),70,true)
        .addImageColumn("IMG", "image", 50, true,ImageScaleMode.FILL_PROPORTIONALLY ,style)
        .addGroups(2)
        .setDetailHeight(17)
        .setTitle("November 2006 sales report")
        .setSubtitle("This report was generated at " + new Date())
        .setUseFullPageWidth(true);

In this code, the key call is

.addImageColumn(<title>, <property>, <width>, <fixed width>, <fill mode> , <style>)

Where

  • title is the title of the column.
  • property is the property of the current element to use as the input for the image. By default the class type is InputStream
  • width of the column
  • fixed column (boolean) if true, the width is mandatory and no resize will be done.
  • fill mode specifies how to deal with the size of the bar code:
    • ImageScaleMode.NO_RESIZE: no resize of the image
    • ImageScaleMode.FILL: stretches the image to fill the rectangle (the with of the column and the height of the detail band)
    • ImageScaleMode.FILL_PROPORTIONALLY: stretches the image proportionally as much as it can to fill the area given to the column.
  • style: (Optional) to give the column horizontal alignment, border, etc…

Other possible call is

addImageColumn(<title>, <property>, <className>, <width>, <fixedWidth>, <imageScaleMode>, <style>)

Where

  • class is the class type of property. Valid types are InputStream and java.awt.Image

This code generate a report like this:

no images were found

Refer to ImageColumnReportTest for a working example.

Fork me on GitHub