- 浏览: 1098696 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
skyesx:
这是2PC实现,更常用的是一个柔性事务的实现,可以参考http ...
Spring分布式事务实现 -
ddbird:
这第一句就不严谨“分布式事务是指操作多个数据库之间的事务”,显 ...
Spring分布式事务实现 -
呵呵6666:
基于互联网支付系统的微服务架构分布式事务解决方案http:// ...
Spring分布式事务实现 -
小黄牛:
写得不错,交流群:472213887
Spring分布式事务实现 -
jiaoqf321456:
这明明是用的apache的压缩,给ant.jar有半毛钱关系吗 ...
使用ant.jar进行文件zip压缩
Barcode4J资源地址:http://barcode4j.sourceforge.net/index.html
一、using the JavaBean API
二、use XML API
1.code39.xml
2.java
3.测试
一、using the JavaBean API
public static void generateCode128Barcode(File file, String code) { Code128Bean bean = new Code128Bean(); final int dpi = 150; //barcode bean.setModuleWidth(0.21); bean.setHeight(15); bean.doQuietZone(true); bean.setQuietZone(2);//两边空白区 //human-readable bean.setFontName("Helvetica"); bean.setFontSize(3); bean.setMsgPosition(HumanReadablePlacement.HRP_BOTTOM); OutputStream out = null; try { out = new FileOutputStream(file); BitmapCanvasProvider canvas = new BitmapCanvasProvider(out, "image/jpeg", dpi, BufferedImage.TYPE_BYTE_BINARY, true, 0); bean.generateBarcode(canvas, code); canvas.finish(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (out != null) out.close(); } catch (IOException e) { e.printStackTrace(); } } } public static void generateCode39Barcode(int mode, File file, String code) { Code39Bean bean = new Code39Bean(); // Dot Per Inch每英寸所打印的点数或线数,用来表示打印机打印分辨率。 final int dpi = 150; // bean.setModuleWidth(UnitConv.in2mm(1.0f / dpi)); bean.setModuleWidth(0.2); bean.setHeight(15); bean.setWideFactor(3); bean.doQuietZone(true); OutputStream out = null; try { out = new FileOutputStream(file); if (mode == 0) { BitmapCanvasProvider canvas = new BitmapCanvasProvider(out, "image/jpeg", dpi, BufferedImage.TYPE_BYTE_GRAY, false, 0); bean.generateBarcode(canvas, code); canvas.finish(); } else { BitmapCanvasProvider canvas = new BitmapCanvasProvider(dpi, BufferedImage.TYPE_BYTE_GRAY, true, 0); bean.generateBarcode(canvas, code); canvas.finish(); BufferedImage barcodeImage = canvas.getBufferedImage(); ImageIO.write(barcodeImage, "jpg", out); } } catch (Exception e) { e.printStackTrace(); } finally { try { if (out != null) out.close(); } catch (IOException e) { e.printStackTrace(); } } }
二、use XML API
1.code39.xml
<?xml version="1.0" encoding="UTF-8"?> <barcode> <code39> <height>15mm</height> <module-width>0.19mm</module-width> <wide-factor>2.5</wide-factor> <interchar-gap-width>1mw</interchar-gap-width> <quiet-zone enabled="true">10mw</quiet-zone> <checksum>ignore</checksum> <human-readable> <placement>bottom</placement> <font-name>Helvetica</font-name> <font-size>8pt</font-size> <display-start-stop>false</display-start-stop> <display-checksum>false</display-checksum> </human-readable> </code39> </barcode>
2.java
/** * 不同的类型,其属性定义有所有同,最好是加载xml文件的方式来配置 */ public static Configuration buildCfg(String barcode_type) { DefaultConfiguration cfg = new DefaultConfiguration("barcode"); DefaultConfiguration barcodeType = new DefaultConfiguration(barcode_type); /** *********属性设置************* */ addChild(barcodeType,"bar-height",15); addChild(barcodeType,"module-width","0.19"); addChild(barcodeType,"quiet-zone",10); addChild(barcodeType,"wide-factor","2.5"); addChild(barcodeType,"interchar-gap-width",1); DefaultConfiguration humanReadable = new DefaultConfiguration("human-readable"); addChild(humanReadable,"placement","bottom"); addChild(humanReadable,"font-name","Helvetica"); addChild(humanReadable,"font-size","3mm"); barcodeType.addChild(humanReadable); cfg.addChild(barcodeType); return cfg; } /** * 添加子节点 * @param parent * @param attrName * @param attrValue */ public static void addChild(DefaultConfiguration parent,String attrName,Object attrValue){ DefaultConfiguration attr; attr = new DefaultConfiguration(attrName); if(attrValue instanceof String) { attr.setValue((String)attrValue); }else{ attr.setValue((Integer)attrValue); } parent.addChild(attr); } /** * 加载xml配置的条形码属性文件 * @param file * @return */ public static Configuration buildCfgFromFile(File file) { DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(); Configuration cfg = null; try { cfg = builder.buildFromFile(file); } catch (Exception e) { e.printStackTrace(); } return cfg; } /** * 生成条形码 * @param barcodeType * @param code * @param file */ public static void generateBarcode(String barcodeType, String code, File file) { byte[] data; ByteArrayOutputStream baos = null; BitmapCanvasProvider bitmap = null; String FORMAT = MimeTypes.MIME_JPEG; int RESOLUTION = 150; int ORIENTATION = 0; try { //加载文件方式 //Configuration cfg = buildCfgFromFile(getResourceFile(barcodeType.concat(".xml"))); Configuration cfg = buildCfg(barcodeType);//程序中的配置属性 BarcodeUtil util = BarcodeUtil.getInstance(); BarcodeGenerator gen = util.createBarcodeGenerator(cfg); baos = new ByteArrayOutputStream(); bitmap = new BitmapCanvasProvider(baos, FORMAT, RESOLUTION, BufferedImage.TYPE_BYTE_GRAY, true, ORIENTATION); gen.generateBarcode(bitmap, code); bitmap.finish(); data = baos.toByteArray(); FileOutputStream out = new FileOutputStream(file); out.write(data); } catch (Exception e) { e.printStackTrace(); } finally { try { if (baos != null) { baos.close(); } bitmap = null; } catch (Exception e) { } } } /** * 取资源文件 * @param fileName * @return */ public static File getResourceFile(String fileName) { String path = ClassLoader.getSystemResource("").getPath().substring(1) + fileName; return new File(path); }
3.测试
public static void main(String[] args) { String code = "ISN8859-52036"; generateCode39Barcode(0, new File("d:/barcode/code39_0.jpg"), code); generateCode39Barcode(1, new File("d:/barcode/code39_1.jpg"), code); generateCode128Barcode(new File("d:/barcode/code128.jpg"), code); generateBarcode("code39", code, new File("d:/barcode/code39.jpg")); }
- barcode4j_lib.rar (317.3 KB)
- 下载次数: 114
发表评论
-
使用zxing.jar生成二维码
2015-10-15 13:52 01、ZxingCodeUtils /** * 使用Zx ... -
Java生成条形码与二维码
2015-09-29 11:02 0一、一维条形码 /** * 利用jbarcode.ja ... -
将html特殊码( &#x)转换成字符
2015-06-09 11:54 0public static void main(St ... -
unicode码的分布情况
2014-06-25 16:33 0******************************* ... -
使用servicemix实现FTP连接池
2013-06-13 13:17 0一、配置文件 <?xml version=" ... -
嵌入式运行HttpServer
2015-06-30 13:14 1749一、嵌入式运行Jetty并提供上传文件功能 1、定义处理请求的 ... -
Windows命令与BAT脚本示例整理
2013-05-30 16:50 0一、将后缀后为".txt-"的文件全部重命 ... -
使用Quartz执行定时任务
2012-05-24 11:00 0一、在application中运用 (1)定义任务 pac ... -
java访问FtpSever
2011-10-09 15:18 0使用apache common-net包来实现。 ... -
有关Hibernate Tools的使用
2010-12-24 15:20 0<一>、生成实体(Entiry)时,自定义反向生成 ... -
使用iText-2.1.7生成PDF
2010-11-25 21:30 0public class PDFUtil { /* ... -
使用iText-2.1.7生成word
2010-11-25 21:17 0public class RTFUtil { pu ... -
FusionCharts参数说明
2010-04-08 12:51 0功能特性 animation ... -
使用ant.jar进行文件zip压缩
2010-02-02 11:40 12485import java.io.BufferedInputS ... -
使用struts2中的codebehind插件
2010-01-11 13:10 0codebehind plugin是一个可以简化struts2 ... -
使用JUnit4
2010-01-04 14:23 3014一、介绍 JUnit4 基本 ... -
Eclipse JPA Plugin
2010-01-04 14:21 8868一、Hibernate Tools Hibernate ... -
关于Apache Mina
2009-11-18 10:13 7514一、介绍 MINA(Multipurpose Infr ... -
json-lib使用
2009-09-16 09:17 15300一、资源链接: http://json-lib.sourcef ... -
apache commons DbUtils
2009-07-22 20:58 9576一、关于DbUtils comm ...
相关推荐
exe4j is a Java exe maker that helps you integrate your Java applications into the Windows operating environment, whether they are service, GUI or command line applications. If you want your own ...
Secure Java: For Web Application Development covers secure programming, risk assessment, and threat modeling—explaining how to integrate these practices into a secure software development life cycle...
Title: Java EE and HTML5 Enterprise Application Development Author: Arun Gupta, Geertjan Wielenga, John Brock Length: 176 pages Edition: 1 Language: English Publisher: McGraw-Hill Osborne Media ...
org.dom4j Defines the XML Document Object Model in Java interfaces together with some helper classes. org.dom4j.bean An implementation of the dom4j API which allows JavaBeans to be used to store and ...
This book describes how to create Instant Messaging applications in Java and covers the Jabber IM protocols. If you want to create new IM systems, integrate them with your existing software, or wish ...
在本系列教程的第六部分,我们将深入探讨如何在C#应用程序中集成图像扫描功能。这一技术对于开发桌面应用,特别是那些处理文档管理、图像处理或需要用户上传实物照片的应用至关重要。我们将关注Scanner.cs和Button...
You will also understand how to achieve authorization in a Spring WebFlux application using Spring Security.You will be able to explore the security confgurations required to achieve OAuth2 for ...
First, we will revise the most important things when starting a Data Science application, and then brush up the basics of Java and Machine Learning before diving into more advanced topics.We start ...
What you will learnIdentify performance bottlenecks in an applicationLocate application hotspots using performance toolsUnderstand the work done under the hood by EE containers and its impact on ...
4. 变体处理 Maximilian Hempe在后续的更新中,详细阐述了使用Groovy脚本进行变体管理以配合E2E Protection Wrapper的策略,这为适应不同环境和配置需求提供了灵活性。 5. 参考文档 为了帮助读者深入理解,文档引用...
With the basics well in hand, you move into interesting examples of ActiveMQ at work, following a running Stock Portfolio application. You'll integrate ActiveMQ with containers like Geronimo and ...
JCONTROL provides an easy way to integrate a full range of java GUIs from the java.awt and javax.swing libraries into MATLAB. Example: obj=JCONTROL(Parent, Style); obj=JCONTROL(Parent, Style,... ...
What you will learnIdentify performance bottlenecks in an applicationLocate application hotspots using performance toolsUnderstand the work done under the hood by EE containers and its impact on ...
Starting with a high level overview of Tkinter that covers the most important concepts involved in writing a GUI application, the book then takes you through a series of real world projects of ...
The book starts with an explanation of what reactive programming is, why it is so appealing, and how we can integrate it in to Java. It continues by introducing the new Java 8 syntax features, such as...
Natural Language Processing (NLP) is an important area of application development and its relevance in addressing contemporary problems will only increase in the future. There has been a significant ...
In conclusion, Log4j is a powerful tool for logging within Java applications. Its hierarchical logger architecture, multiple output formats, and performance optimizations make it a preferred choice ...