Display Barcode __import in birt2.1.2

Source: Internet
Author: User
Bar code display, the most common in Birt two methods: 1, using barcode font (invalid for pdf), 2, with barcode Open source package, generate barcode, and then use dynamic address in the report to take pictures.

Look at the Birt document tonight (the 23rd chapter uses Java to write event handlers), in the example of Java implementation of a Labeleventadapter adapter, the label element for event control. The brain is a flash, it seems that the bar code has fallen.

My test example is simple, inheriting the Imageeventadapter class, overloading the OnCreate method for barcode processing

1 package cn.ynzc.common.birt.test;
2
3 Import Java.io.File;
4 Import Java.io.FileOutputStream;
5
6 Import Jbarcodebean. Code128;
7 Import Jbarcodebean. Jbarcodebean;
8
9 Import Org.apache.commons.codec.digest.DigestUtils;
Import Org.eclipse.birt.report.engine.api.script.IReportContext;
Import Org.eclipse.birt.report.engine.api.script.eventadapter.ImageEventAdapter;
Import org.eclipse.birt.report.engine.api.script.instance.IImageInstance;
13
public class Mylabelclass extends Imageeventadapter {
15
public void OnCreate (iimageinstance image, Ireportcontext reportcontext) {
The try {
18//practical applications, you can use Image.getrowdata (). GetColumnValue ("ColumnName") to get field values
String code = "abcdef123-2222";
20//It seems that the "-" symbol is not allowed in Windows filename, simply md5 the code for hashing
File File = new file (System.getproperty ("Java.io.tmpdir"), Digestutils.md5hex (code));
22//Avoid every time the barcode file generation
if (! file.exists ()) {
Jbarcodebean BB = new Jbarcodebean ();
Bb.setcodetype (New Code128 ());
Bb.setshowtext (TRUE);
Bb.setbarcodeheight (45); Bar code Height
Bb.setcode (code);
Bb.gifencode (new FileOutputStream (file));
30}
Image.setfile (File.getabsolutepath ());
32}
catch (Exception e) {
E.printstacktrace ();
35}
36}
37
38}
39
The Test Birt report file is simply dying, throw an image element on it, set its event Handler class for the Java class just written, and the resulting rptdesign file is as follows:
1.? XML version= "1.0" encoding= "UTF-8"?>
2 <!--written by Eclipse BIRT 2.0-->
3 < "xmlns =" http://www.eclipse.org/birt/2005/design "Version =" 3.2.6 "id =" 1 ">
4 < property name = ' CreatedBy ' > Eclipse BIRT Designer Version 2.1.2.v20070205-1728 Build &lt; 20070205-1728> </Property >
5 < property name = "Units" > on </property >
6 < Page-setup >
7 < Simple-master-page name = "simple MasterPage" id = "2"/>
8 </page-setup >
9 < BODY >
< image id = "4" >
< property name = "Eventhandlerclass" > Cn.ynzc.common.birt.test.MyLabelClass </Property >
</Image >
</Body >
</>
Run the test, the barcode came out


Legacy issues:
This time it is called org.eclipse.birt.report.engine.api.script.instance.IImageInstance.setFile () to solve the problem, which can be seen from Javadoc, There are many ways that iimageinstance can be invoked, and how other methods work. For example, I tried a half-day SetData (byte[]) method, the first thought is to use this method directly to the graphic data set into the OK, the results were unsuccessful.
Ext: http://www.blogjava.net/mmwy/archive/2007/04/07/109052.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.