`

Java生成条形码

    博客分类:
  • java
阅读更多
条形码介绍: 
       条形码或称条码(barcode)是将宽度不等的多个黑条和空白,按照一定的编码规则排列,用以表达一组信息的图形标识符。常见的条形码是由反射率相差很大的黑条(简称条)和白条(简称空)排成的平行线图案。条形码可以标出物品的生产国、制造厂家、商品名称、生产日期、图书分类号、邮件起止地点、类别、日期等信息,因而在商品流通、图书管理、邮政管理、银行系统等许多领域都得到了广泛的应用。
条形码参考:
       http://www.barcodelib.com/java_barcode/main.html
       http://www.barcodelib.com/java_barcode/file_download.php
生成条形码代码:
import java.awt.Font;
import com.barcodelib.barcode.Linear;

public class Test {
 public enum Type{
  CODABAR,CODE11,UOM_PIXEL,CODE2OF5,CODE39,CODE39EX,CODE93,EAN8,EAN8_2,EAN8_5,
  EAN13,EAN13_2,EAN13_5,ISBN,ISBN_5,ISSN,ISSN_2,ITF14,INTERLEAVED25,IDENTCODE,
  LEITCODE,MSI,ONECODE,PLANET,POSTNET,RM4SCC,UPCA,UPCA_2,UPCA_5,UPCE,UPCE_2,
  UPCE_5,CODE128,EAN128
 }
 
    /**
     * 条形码
     *
     * @throws Exception
     */
    static void barcode(String file,int type) throws Exception{
        Linear barcode = new Linear();
        barcode.setType(type);//设置条形码的类型
        barcode.setData("123456789"); //设置数据
        barcode.setN(2f); //设置宽条与窄条的比例。有效值为2.0F至3.0f,包容性。默认为2.0F
        barcode.setUOM(Linear.UOM_PIXEL);//设置单位为像素
        barcode.setX(3f);//设置每条宽度为3像素
        barcode.setY(45f);//设置高度为45像素
        //设置左右上下的边距
        barcode.setLeftMargin(0f);
        barcode.setRightMargin(0f);
        barcode.setTopMargin(0f);
        barcode.setBottomMargin(0f);
       
        barcode.setResolution(72); //设置分辨率
        barcode.setShowText(true);//设置显示下面的数字或字母
        barcode.setTextFont(new Font("Arial", 0, 12));//设置字体
        barcode.setRotate(Linear.ANGLE_0); //设置旋转度
       
        barcode.setAddCheckSum(false);//添加验证
        barcode.renderBarcode(file);
    }
 
    /**
     * @param args
     * @throws Exception
     */
    public static void main (String[] args) throws Exception{
     barcode("d://codabar.gif",Linear.CODABAR);
    }
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics