Barcode4J由Java语言编写而成,可以灵活的毕胡生成条形码。它采用Apache License V2.0许可,这使得它很容易在商业中被使用。它可以让您生成各种流行的一维和二维条码,包括DataMatrix 和 PDF417。以各种格式输出,包括SVG, EPS, bitmaps和Java2D,手型拦同样也可根据您的需要添加自己的输出格式租贺。它为各种应用提供了插件,包括最重要的Apache FOP(格式对象处理器)。
创新互联专业为企业提供淄博网站建设、淄博做网站、淄博网站设计、淄博网站制作等企业网站建设、网页设计与制作、淄博企业网站模板建站服务,10余年淄博做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
localJBarcode.setPainter(WideRatioCodedPainter.getInstance()); 输出槐岁条谈明态码
localJBarcode.setTextPainter(BaseLineTextPainter.getInstance()); 输含源出文本
现在代码共享如下,仅供参考因为本人还历卖不精通。
package com.prodPrint;
import java.io.File;
import java.util.HashMap;
import org.eclipse.swt.SWT;
import org.eclipse.swt.ole.win32.OleAutomation;
import org.eclipse.swt.ole.win32.OleControlSite;
import org.eclipse.swt.ole.win32.OleFrame;
import org.eclipse.swt.ole.win32.Variant;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import com.lppx2.OleDispatch;
public class ActiveXPrinter extends Composite{
private OleFrame myFrame = new OleFrame(this, SWT.NONE);
// Microsoft Internet Explorer ProgID: Shell.Explorer.2
/肢穗逗/ Codesoft ProgID : Lppx2.Application
private String progId = "Lppx2.Application"族岁;
private OleControlSite controlSite;
private OleAutomation automation
private OleDispatch appActiveDoc;
private OleDispatch appDocs;
File currentFile;
public ActiveXPrinter(Composite parent, int style) {
super(parent, style);
myFrame = new OleFrame(this, SWT.NONE);
controlSite = new OleControlSite(myFrame, SWT.NONE, progId);
automation = new OleAutomation(controlSite);
}
public void print (String fileName) {
currentFile = new File(fileName);
initialize();
}
private void initialize() {
try{
Variant documents = (new OleDispatch(automation)).Invoke("Documents",new Variant[0]);
appDocs = new OleDispatch(documents.getAutomation());
if (!currentFile.canRead() ) {
System.out.println("Unable to read file : " + currentFile);
} else {
Variant file[] = new Variant[1];
file[0] = new Variant(currentFile.getAbsolutePath());
if (appDocs.Invoke("Open", file) != null) {
System.out.println(currentFile.getAbsolutePath() + " is opened now");
} else {
System.out.println("Unable to open " + currentFile.getAbsolutePath());
}
Variant activeDocumentV = (new OleDispatch(automation)).Invoke(
"ActiveDocument", new Variant[0]);
try {
appActiveDoc = new OleDispatch(activeDocumentV.getAutomation());
} catch (Exception excpt) {
}
Variant[] quantity = new Variant[1];
quantity[0] = new Variant(1);
if (appActiveDoc.Invoke("PrintDocument", quantity) != null)
System.out.println("Print OK");
else {
System.out.println("Unable to print !");
}
}
}catch(Exception excpt) {
System.out.println("You can't print anything until a document is opened !");
excpt.printStackTrace();
return;
}
}
public static void main(String[] args) {
Display display = Display.getDefault();
Shell shell = new Shell(display);
new ActiveXPrinter(shell, 0).print("C:\Document1.Lab");
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
public class Ean13Barcode {
private String code;
public Ean13Barcode(String code) {
super();
this.code = code;
}
public String encode() {
if (null == code) {
return "";
}
char[] codes = code.toCharArray();
int sum = 0;
for (int i = 0; i codes.length; i++) {
int num = codes[i] - '0';
if (isEven(num)) {
sum += num;
} else {
sum += num * 3;
}
}
int x = sum % 10;
return code + (x == 0 ? 0 : 10 - x);
}
private boolean isEven(int x) {
return x % 2 == 0;
}
public static void main(String[] args) {
System.out.println(new Ean13Barcode("692223361219").encode());
}
}