I. Description
Finereport comes with EAN code, but there is no UPC barcode. What should you do if you want to use UPC barcode in the report? Finereport can reference the third-party package through the custom function to generate and display the UPC barcode. If you enter the value 12345678912, you will get the following UPC barcode:
II. Principle
Since the advent of bar code, in order to meet a variety of needs, many coding systems have been produced. But at present, there are mainly two kinds of packaging, UPC and EAN. The two coding systems belong to the same type, each character is composed of several black and white stripes, with two narrow stripes extending down a little, which divides the bar code into two parts. Although these two kinds of bar codes can only represent 10 digits from 0 to 9 , they have high checking ability, simple and reliable scanning operation. The composition of UPC is composed of 11 digit general product code and 1 digit check code. The first digit of the product code is the coding system character; the middle five digits indicate the manufacturer name, and the last five digits are the product code.
III. Operation steps
1. Writing custom functions
1) Import third party package
Import the third party package (barcode4j-light.jar)in Eclipse. Barcode4j is an open source barcode generation library, which can generate many kinds of barcode, including UPC code. Custom functions can directly call the existing methods in the package to generate UPC barcode.
2) Custom function class
Create a new UPC class. For the complete code, see:
2. Compiling custom functions
compile Upc.class file generated by Upc.java , copy to report environment directory %fr_ Home%/webapps/Webroot/WEB-INF/classes/com/FR/function;
Put the third party package barcode4j-light.jarin report environment directory %FR_HOME%/webapps/webroot/WEB-INF/lib.
3. Registering user defined functions
Start the designer, click server > function manager, name the new function UPC, select Upc.class, as shown in the figure below:
4. Use of upc() function
Restart the server and use the formula = Upc (num1, num2) in the report. Num1 is the value to generate the barcode and num2 is the height of the generated image.
If you enter the formula in the cell: = Upc (12345678912,100), you can see the bar code in the preview.