This post originated from an RSS feed registered with Java Buzz
by Marc Logemann.
Original Post: Embed barcodes in Birt w/o barcode fonts
Feed Title: Logemann Blog
Feed URL: http://feeds.feedburner.com/LogemannBlog
Feed Description: Marc Logemann's thoughts on java and other stuff
I recently switched my report framework to Birt. Its a quite powerful framework but it doesnt have a barcode component which you can use out of the box. But if you use the Birt Runtime Engine (RE) API, you can easily create your barcode with a suitable library (like RBarcode) capable of creating barcode images and supply these "raw" images to the Birt RE.
I wont tackle the whole bootstrapping stuff of Birt, this can be researched in their docs quite easily. So lets start with
// get engine from normale Birt Bootstrapping... // ... design = engine.openReportDesign("/Users/reports/foo.rptdesign"); //create task to run and render report IRunAndRenderTask task = engine.createRunAndRenderTask(design);
//set output options PDFRenderOption options = new PDFRenderOption(); options.setOutputFileName("output/foo.pdf"); options.setOutputFormat("pdf");
task.setRenderOption(options);
// bos is a ByteOutputStream containing the // raw image from a barcode library byte[] bytes = bos.toByteArray(); task.getAppContext().put("imageBarcode", bytes);
//run and render report task.run(); task.close();
So this was a simple Main Class using a Birt Engine to dynamicly put a byteArray to a report Context and run the report. Now do the following in the Report Designer:
Put an image on the report
Define "Dynamic Image" as Type
click "Select Image Data" Button
In the DataBinding Dialog click the "Add..." Button
check the checkbox in front of the "foo" entry in dialog
Thats it. If everything worked fine, the dialogs should look like below. When you now run your report the barcode should be visible where you placed the image container.