Menu

HOME > SUPPORT > IMAGE SUBSTITUTION

Image Substitution

 

Overview

Most ReportMill customers are very familiar with the text substitution that forms the core of report generation. ReportMill turns tags such as "@Date@" and "Page @Page@ of @PageMax@" into text such as "October 21, 1999" and "Page 1 of 12".

However, ReportMill offers another very powerful form of data substitution in the Image Substitution feature. This feature is very useful for embedding images in a report which need to change from report to report (or even from table row to table row)- whether they come from a product image database, the filesystem or a graphics library.

To utilize this feature, simply select the Tools->Add Image Placeholder menu item.

Set Image Key

When you select the Image placeholder, the inspector will show the attributes of the placeholder. The "Key" field allows you to specify the key or expression that will provide the image data. Simply enter or drag in the key or expression to this field.

Usually, this key will be a simple key (like getLogo, getImageData, etc.) but it can be any complex ReportMill expression. Here's an example of how you might construct an image key that uses an actual web service that can return a barcode image, given a number.

"http://bcgen.com:7001/ida/servlet/LinearServlet?BARCODE=" + getProductID

Value Types

With image substitution, ReportMill expects the supplied key to resolve to one of the following types of objects: String, byte[], File or URL. ReportMIll supports the following image types: GIF, TIFF, JPEG, PNG, BMP, and PDF.

Passing a String Value

If you are providing a string, it should be an absolute path to a file in the file system or a URL to a image available via an HTTP service.

Passing a Byte Array

If you provide a byte array (byte[]), it should be exactly the bytes of an image file as it would appear on disk.

Providing Image Data in UserInfo

If you added your image placeholder at the root level of your document (or perhaps in the header row of a table) you'll probably want to provide the image data in the UserInfo. The UserInfo parameter is designed for providing this type of additional information. It can be a simple Java.util.Map with a key called "MyImage" corresponding to a value of type String, byte array, etc.

Tables: Providing Image Data as an Object Method or Attribute

ReportMill performs image substitution using the exact same mechanism as text substitution. If you added your image placeholder to a detail table row, ReportMill will try to evaluate the image key against your table objects (perhaps to show a different image in each row) and use UserInfo as a fallback. This would be the case if you had an Employee object with a method called employeePicture, which returned image data. The key might look like "employeePicture" and return a byte[] loaded from the database.

Image Sources

Customers have used the image substitution facility to add graphs to their reports from sources such as NetCharts (www.chartworks.com), Pop Charts (www.corda.com) or other graphing libraries. Any source that can provide image data in the aforementioned formats can be used in conjunction with ReportMill.

An Example

Here's an example of a simple stand-alone Java class that generates a report from an object that knows how to generate a chart using Java 2D: [RMImageTest.java] [RMImageTest.pdf]