Java生成条形码
用JAVA显示各种规格的条形码(18种),打印后可以被扫描设备扫描,JAVA中要生成条形码码的方法如下:
1.需要一个jar包的支持,这里用的是barbecue-1.5-beta1.jar;
2.接下来就可以编写相关程序;
4.编写JSP页面
<%@ page contentType="text/html;charset=UTF-8"%>
<%
String code = "135792468";//条形码内容
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
function window.onbeforeprint() {
eval(visble_property_printview + " = \"" + visble_property_false + "\"");
}
function window.onafterprint() {
eval(visble_property_printview + " = \"" + visble_property_true + "\"");
}
//-->
bottommargin="0px">
<%
StringBuffer barCode = new StringBuffer();
barCode.append("");
//barCode.append("'>");
out.println(barCode.toString());
%>
style="cursor:hand;" onclick="nowprint();">
src="${path}CreateBarCode?data=123456789&barType=CODE39&checkCharacter=n&checkChar acterInText=n"/>
<%=barCode %>
5.条形码码的一些相关参数如下:
5.1. barType(默认为CODE128): 条码类型.支持18钟类型,分别是
CODE39,CODE39EXT,INTERLEAVED25,CODE11,CODABAR,MSI,UPCA,IND25,MAT25,CODE 93,EAN13,EAN8,UPCE,CODE128,CODE93EXT,POSTNET,PLANET,UCC128 .
5.2. code: 要打印的条码内容.
5.3. width(默认为自适应,一般不用自行设置): 图片宽度.width,height要同时
都设置才有效.
5.4. height(默认为自适应,一般不用自行设置): 图片高度.width,height要同时都设置才有效.
5.5. st(默认为y显示): 是否显示条码内容(show text).默认会在条码图片下方显示条码内容,有效值为y和n.
5.6. textFont(默认为Arial|PLAIN|11): 条码文本的字体,字体有效格式为|