如何利用ireport实现打印条码标签

如何利⽤ireport实现打印条码标签
上个星期做了⼀个⽤ireport打印条码标签的需求,其实有打印条码有很多专门的软件,例如ZebraDesigner,但是ireport可以和java结合起来,使⽤起来⽐较⽅便,现简要叙述⼀下过程:
  1、打开ireport,新建⼀个⽂档,⽤⿏标点击图标拖拽到⽂档⾥,这⾥不累述ireport的使⽤⽅法,ireport的使⽤说明书可以到⽹上下载。
  2、双击,打开它的属性框,选择图⽚栏,在图⽚表达式⾥输⼊条码转换的⽅法,可以查阅如下代码:
  3、注意图⽚表达式类选择java.awt.Image
        /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * www.jaspersoft.
4  *
摩托罗拉a668
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see /
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
上海施贵宝
24  *
25  *
26  *
27  * BcImage.java
28  *
29  * Created on 20. April 2004, 13:21
30  *
31  */
32
33 package it.businesslogic.ireport.barcode;
34
35 /**
36  *
37  * @author Heiko
38  */
40 import java.awt.image.*;
41 import net.sourceforge.barbecue.*;
42 import net.sourceforge.barbecue.linear.ean.UCCEAN128Barcode;
43
44 public class BcImage {
45    private static net.sourceforge.barbecue.Barcode bc = null;
46
47    public static net.sourceforge.barbecue.Barcode getBarcode() {
48        return bc;
49    }
50
51        public static BufferedImage getBarcodeImage(int type,  aText, boolean showText, boolean checkSum) {
52            return getBarcodeImage(type, aText, showText, checkSum,"",0,0);
正硅酸乙酯
53        }
54
55    public static BufferedImage
getBarcodeImage(int type,  aText, boolean showText, boolean checkSum,  applicationIdentifier, int width, int height) {
56        // 2of7, 3of9, Bookland, Codabar, Code128, Code128A, Code128B, Code128C, Code39, EAN128, EAN13, GlobalTradeItemNumber, Int2of5, Int2of5, Monarch, NW7, PDF417, SCC14ShippingCode, ShipmentIdentificationNumber, SSCC18, Std2of5, Std2of5, UCC128, UPCA, USD3, USD4, USPS
57
58          text = new  ().append(aText).toString();
59
60        try {
61            switch (type) {
62                                case 0: return null;
63                                case 1: bc = ate2of7(text); break;
64                case 2: bc = ate3of9(text, checkSum); break;
65                case 3: bc = ateBookland(text); break;
66                case 4: bc = ateCodabar(text); break;
67                case 5: bc = ateCode128(text); break;
68                case 6: bc = ateCode128A(text); break;
69                case 7: bc = ateCode128B(text); break;
70                case 8: bc = ateCode128C(text); break;
71                case 9: bc = ateCode39(text, checkSum ); break;
朱时华
72                case 10: bc = ateEAN128(text); break;
73                case 11: bc = ateEAN13(text); break;
74                case 12: bc = ateGlobalTradeItemNumber(text); break;
75                case 13: bc = ateInt2of5(text, checkSum); break;
76                case 14: bc = ateMonarch(text); break;
77                case 15: bc = ateNW7(text); break;
78                case 16: bc = atePDF417(text); break;
79                case 17: bc = ateSCC14ShippingCode(text); break;
80                case 18: bc = ateShipmentIdentificationNumber(text); break;
81                case 19: bc = new UCCEAN128Barcode(UCCEAN128Barcode.SSCC_18_AI, text,
checkSum); break; //ateSSCC18(text); break;
82 case 20: bc = ateStd2of5(text, checkSum); break;
83                case 21: bc = new UCCEAN128Barcode(applicationIdentifier, text,
checkSum); break; //ateUCC128(applicationIdentifier, text); break;
84 case 22: bc = ateUPCA(text); break;
85                case 23: bc = ateUSD3(text, checkSum); break;
86                case 24: bc = ateUSD4(text); break;
87                case 25: bc = ateUSPS(text); break;
88                                case 26: bc = new net.sourceforge.de39.Code39Barcode(text, checkSum, true); break;
89            }
90
91                        if (width > 0) bc.setBarWidth(width);
92                        if (height > 0) bc.setBarHeight(height);
93            bc.setDrawingText(showText);
94            return net.sourceforge.Image(bc);
95        }
96        catch (  e) {协作学习
97            e.printStackTrace();
98            //generate a runtime exception, invalid value passed.
99 //the user must be notified if fail
100 throw new  (e.getMessage());
医学新知杂志101            //return null;
103    }
104 }
附:更多开源代码查阅可到   

本文发布于:2024-09-23 04:27:26,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/292635.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:条码   打印   查阅   起来   标签   表达式
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议