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

 我来答
福喜900
2015-01-16 · TA获得超过6.1万个赞
知道大有可为答主
回答量:1.1万
采纳率:0%
帮助的人:1亿
展开全部
利用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 * htt p:/ /ww w.ja sperso ft.co m.
4 *
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 htt p:/ /ww w.g n u.or g/licenses/gpl.txt
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 */
39
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, Object aText, boolean showText, boolean checkSum) {
52 return getBarcodeImage(type, aText, showText, checkSum,"",0,0);
53 }
54
55 public static BufferedImage getBarcodeImage(int type, Object aText, boolean showText, boolean checkSum, String 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 String text = new StringBuffer ().append(aText).toString();
59
60 try {
61 switch (type) {
62 case 0: return null;
63 case 1: bc = BarcodeFactory.create2of7(text); break;
64 case 2: bc = BarcodeFactory.create3of9(text, checkSum); break;
65 case 3: bc = BarcodeFactory.createBookland(text); break;
66 case 4: bc = BarcodeFactory.createCodabar(text); break;
67 case 5: bc = BarcodeFactory.createCode128(text); break;
68 case 6: bc = BarcodeFactory.createCode128A(text); break;
69 case 7: bc = BarcodeFactory.createCode128B(text); break;
70 case 8: bc = BarcodeFactory.createCode128C(text); break;
71 case 9: bc = BarcodeFactory.createCode39(text, checkSum ); break;
72 case 10: bc = BarcodeFactory.createEAN128(text); break;
73 case 11: bc = BarcodeFactory.createEAN13(text); break;
74 case 12: bc = BarcodeFactory.createGlobalTradeItemNumber(text); break;
75 case 13: bc = BarcodeFactory.createInt2of5(text, checkSum); break;
76 case 14: bc = BarcodeFactory.createMonarch(text); break;
77 case 15: bc = BarcodeFactory.createNW7(text); break;
78 case 16: bc = BarcodeFactory.createPDF417(text); break;
79 case 17: bc = BarcodeFactory.createSCC14ShippingCode(text); break;
80 case 18: bc = BarcodeFactory.createShipmentIdentificationNumber(text); break;
81 case 19: bc = new UCCEAN128Barcode(UCCEAN128Barcode.SSCC_18_AI, text, checkSum); break; //BarcodeFactory.createSSCC18(text); break;
82 case 20: bc = BarcodeFactory.createStd2of5(text, checkSum); break;
83 case 21: bc = new UCCEAN128Barcode(applicationIdentifier, text, checkSum); break; //BarcodeFactory.createUCC128(applicationIdentifier, text); break;
84 case 22: bc = BarcodeFactory.createUPCA(text); break;
85 case 23: bc = BarcodeFactory.createUSD3(text, checkSum); break;
86 case 24: bc = BarcodeFactory.createUSD4(text); break;
87 case 25: bc = BarcodeFactory.createUSPS(text); break;
88 case 26: bc = new net.sourceforge.barbecue.linear.code39.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.barbecue.BarcodeImageHandler.getImage(bc);
95 }
96 catch (Exception e) {
97 e.printStackTrace();
98 //generate a runtime exception, invalid value passed.
99 //the user must be notified if fail
100 throw new RuntimeException (e.getMessage());
101 //return null;
102 }
103 }
104 }
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
信飞智创
2024-11-26 广告
二维码防伪标签的制作涉及多个步骤。首先,设计防伪元素,如独特的图案和文字,确保难以仿制。接着,选择可信赖的二维码生成工具,为每个标签生成标识码。随后,将防伪元素嵌入二维码图案中,并选择合适材料进行印刷。印刷完成后,对标签进行质检,确保符合设... 点击进入详情页
本回答由信飞智创提供
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式