Generate a bar code using Java and use barcode4j

Source: Internet
Author: User

Recently, a barcode was used in the OA system. At first, I called the company that sold the barcode printer (because the customer bought it from him) to check whether some interface specifications can be provided, the result is that you can provide interfaces, but you have to pay for them. If you want to forget it, you can find your own solution on the Internet. After checking the information, I feel that barcode4j is still quite easy to use. I would like to share my experiences with you briefly.

1. First, I downloaded the barcode4j-2.0alpha2-src.zipzip package at http://barcode4j.krysalis.org.

2, extract this package, decompress the barcode4j-2.0alpha2-src.zip package, in the lib directory has a avalon-framework-4.2.0.jar, commons-cli-1.0.jar, add these two jar files to the project Lib, then add the two jar packages to the classpath in the project configuration. Copy the source code under src/Java/to your src directory and open arcodeservlet under the org/krysalis/barcode4j/servlet directory. java class, modify the default image display mode, barcodeservlet. about 168th lines of Java mimetypes. change mime_svg to mimetypes. mime_jpeg (because not all browsers support the SVG format ).

3. Configure the following servlet in Web. xml
<Servlet>
<Servlet-Name> barcodeservlet </servlet-Name>
<Servlet-class> org. krysalis. barcode4j. servlet. barcodeservlet </servlet-class>
</Servlet>

<Servlet-mapping>
<Servlet-Name> barcodeservlet </servlet-Name>
<URL-pattern>/barcode </url-pattern>
</Servlet-mapping>

4. Add /barcode? MSG = 12345678 "/>

5. It supports the following types:
Code128 is used by default. You can control the display type through parameter settings.
/barcode? MSG = 12345678 & barcode_type = code39 "/>
You can also set the width and height, and do not display numbers. You can view the source code by yourself.

Lircode39: The 39 code has only two unit widths: The width unit and the narrow unit. The width of a unit is one to three times that of a narrow unit. Generally, 2 times, 2.5 times, or 3 times are used for multiple units. Each bar code character of 39 yards consists of nine units, three of which are width units, and the rest are narrow units. Therefore, it is called 39 yards.
39 characters in length, which can indicate letters, numbers, and other symbols. A total of 43 characters: A-Z, 0-9 ,-. $/+ %. The length of the space bar code can be changed. Generally, "*" is used as the start and end character. The verification code does not have to have a code density of 3 to characters/inch, the blank area is 10 times that of a narrow bar and is used for automated management of industries, books, and tickets.

Code39ext: The full ascii39 code is an extension of the 39 code usage. It uses the Standard 39 code and bar code characters and uses a combination of specific methods to represent the 128 characters of the ASCII character set.

Code93: 93 uses the same character set as 39, but its barcode density is higher than 39

Interleaved25: The cross 25 code is a variable-length continuous self-verification digital code system,
Its character set is numbers 0-9,
The width of each element is either wide or narrow.
The number of encoded characters is an even number. All data at the odd position is encoded in strips, and data at the even position is encoded in null.
If it is an odd number of data encodings, add a digit 0 before the data so that the data is an even number.

Ind25: Industrial 25 code, which can only use numbers. Different from the cross 25 code, all its information is recorded in the bar code line. The bar code blank is only used to separate bar code lines.

Code11: code11 code, valid Character Set: 0123456789-

Code128: The code128 Code represents a total of 127 ASCII characters from ASCII 0 to ASCII 128. It is widely used because of its large character set and high density.
The International UCC/EAN organization has a special code identification standard for the code 128, that is, the UCC/ean128 code, which provides unified coding specifications and explanations globally.

Codabar: kudaba code is a widely used barcode in medical and book fields. Its Character Set is 0 to 9, with 10 digits, four letters "ABCD", and "$ -: /. + "six special characters, where" ABCD "is only used as the start and end characters and can be combined in any way.

Msi: The MSI code can only use numbers, mainly used in libraries and retail.

 

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.