JAVA条形码生成组件barcode4j使用

用java生成条形码,barcode4j得应用
   1.去http://barcode4j.sourceforge.net/下载文件,(源代码和生成好的都要下载)

    2.解压barcode4j-2.0alpha2-bin.zip这个包,在build目录下有barcode4j.jar,在lib目录下有avalon-framework-4.2.0.jar, 将barcode4j.jar和avalon-framework-4.2.0.jar添加到项目的lib中,eclipse中只要复制到web-inf下面的lib里面就OK了.

    3.解压将barcode4j-2.0alpha2-src.zip,将srcjavaorgkrysalisbarcode4jservlet目录下的BarcodeServlet.java类的代码拷出来,修改默认的图片显示方式,找到        if (format == null) format = MimeTypes.MIME_JPEG;这一行,表示默认的格式为JPEG文件

    4.将以下这段servlet配置在web.xml中

 <servlet>
    <servlet-name>BarcodeServlet</servlet-name>
    <servlet-class>com.yourname.BarcodeServlet</servlet-class>
    </servlet> 
    <servlet-mapping>
    <servlet-name>BarcodeServlet</servlet-name>
    <url-pattern>/barcode</url-pattern>
    </servlet-mapping>
 


    5.在页面中添加<img src="<%=request.getContextPath() %>/barcode?msg=12345678" height="50px" width=130px/>

    type是生成条形码的类型:

    看例子就明白了

  <table border="1">
       <tr>
       <td>
       <h1>code39</h1>
       <img src="<%=request.getContextPath()%>/barcode?msg=0123456789&type=code39" height="100px" width=300px/>
       </td>
       <td>
       <h1>code128</h1>
       <img src="<%=request.getContextPath()%>/barcode?msg=0123456789&type=code128" height="100px" width=300px/>
    </td>
    <td>
       <h1>Codabar</h1>
       <img src="<%=request.getContextPath()%>/barcode?msg=0123456789&type=codabar" height="100px" width=300px/>
    </td>
    </tr>
    <tr>
    <td>
    <h1>intl2of5</h1>
       <img src="<%=request.getContextPath()%>/barcode?msg=01234567890540&type=intl2of5" height="100px" width=300px/>
    </td>
    <td>
    <h1>upc-a</h1>
       <img src="<%=request.getContextPath()%>/barcode?msg=012345678912&type=upc-a" height="100px" width=300px/>
    </td>
    <td>
    <h1>ean-13</h1>
       <img src="<%=request.getContextPath()%>/barcode?msg=200123457893&type=ean-13" height="100px" width=300px/>
    </td>
    <td>
    <h1>ean-8</h1>
       <img src="<%=request.getContextPath()%>/barcode?msg=20123451&type=ean-8" height="100px" width=300px/>
    </td>
    </tr> 
    <tr>
    <td>
    <h1>postnet</h1>
       <img src="<%=request.getContextPath()%>/barcode?msg=01234567890540&type=postnet" height="100px" width=300px/>
    </td>
    <td>
    <h1>royal-mail-cbc</h1>
       <img src="<%=request.getContextPath()%>/barcode?msg=012345AS678912&type=royal-mail-cbc" height="100px" width=300px/>
    </td>
    <td>
    <h1>pdf417</h1>
       <img src="<%=request.getContextPath()%>/barcode?msg=200123457893&type=pdf417" height="100px" width=300px/>
    </td>
    <td>
    <h1>datamatrix</h1>
       <img src="<%=request.getContextPath()%>/barcode?msg=20123451&type=datamatrix" height="100px" width=300px/>
    </td>
    </tr>
    </table>
 

lirCODE39: 39码仅有两种单元宽度,分别为宽单元和窄单元。宽单元这宽度为窄单元的1到3倍,一般多选用2倍、2.5倍或3倍。39码的每一个条码字符由九个单元组成,其中有三个宽单元,其余是窄单元,因此称为39码 
39码,能表示字母、数字和其它一些符号共43个字符:A-Z,0-9,-.$/+%,空格条码的长度是可变化的,通常用“*”号作为起始、终止符,校验码不用代码密度介于3-9.4个字符/每英寸,空白区是窄条的10倍,用于工业、图书、以及票证自动化管理上

CODE39EXT: 全ASCII39码是39码的一种扩展用法,它利用标准39码和条码字符,经特定方法组合而表示ASCII字符集的128个字符.

CODE93: 93码使用与39码完全相同的字符集,但它的条码密度要比39码高

INTERLEAVED25: 交叉25码是一种长度可变的连续型自校验数字式码制, 
其字符集为数字0-9, 
采用两种元素宽度,每个条和空是宽或窄元素。 
编码字符个数为偶数,所有奇数位置上的数据以条编码,偶数位置上的数据以空编码。 
如果为奇数个数据编码,则在数据前补一位0,以使数据为偶数个数位

IND25: 工业25码,只能使用数字.跟交叉25码不同,它所有的信息都记录在条码线条中,条码空白只用来分隔条码条.

CODE11: Code11码,有效字符集为0123456789-

CODE128: Code128码可表示ASCII 0到ASCII 127共计128个ASCII字符,由于其字符集大,密度高,应用非常广泛。 
国际UCC/EAN组织有一个专门的关于128码的条码标识标准,就是UCC/EAN128码,这种128码在全球范围内有统一的编码规范和解释。

CODABAR: 库德巴码是一种广泛应用在医疗和图书领域的条码,其字符集为0到9共10个数字、“ABCD”四个字母和“$-:/.+”六个特殊字符,其中“ABCD”仅作为启始符和终止符,并可任意组合。

MSI: MSI码只能使用数字,主要用于图书馆和零售业.

转载于:https://my.oschina.net/usenrong/blog/197814

猜你喜欢

转载自blog.csdn.net/weixin_33962621/article/details/92028965