Generating UPC barcode by custom function

  • Last update:January 14, 2021
  • 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:

    image.png

    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:

    https://github.com/finereport-overseas/example/blob/release/10.0/src/main/java/com/fr/function/Upc.java


    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:

    企业微信截图_16080831024958.png


    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.

    企业微信截图_16080831473453.png




    Attachment List


    Theme: Secondary Development
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    9s后關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy