可以使用搜索查找您的内容

JAVA调用CODESOFT打印条形码标签

UDI / CODESOFT动态  / JAVA调用CODESOFT打印条形码标签

JAVA调用CODESOFT打印条形码标签

CODESOFT提供了非常丰富的接口,并且开放了几乎可控制CODESOFT一切功能的权限,目前,几乎所有的ERP、MES等系统都集成了CODESOFT的条码打印功能。

有些使用JAVA语言的IT工程刚刚接触CODESOFT,可能不知道如何调用CODESOFT,以及不知道如何将数据传输给CODESOFT的条码标签。

CODESOFT的条码标签的后缀名是.lab,本文,提供了一下参考代码,让大家参考如何调用CODESOFT的lab条码标签文档并打印出来。

CODESOFT条码软件

CODESOFT条码软件

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();
}
}

————————————————————————————

package com.prodPrint;

import org.eclipse.swt.ole.win32.OleAutomation;
import org.eclipse.swt.ole.win32.Variant;

public class OleDispatch {
public OleAutomation oa;

public OleDispatch(OleAutomation oa) {
this.oa = oa;
}

public Variant Invoke(String name, Variant[] arg) {
if (oa != null) {
int[] cmdId = oa.getIDsOfNames(new String[] { name });
if (cmdId != null) {
return oa.invoke(cmdId[0], arg);
} else {
return null;
}
} else {
return null;
}
}

public String Invoke2(String name, Variant arg[]) {
int cmdId[] = oa.getIDsOfNames(new String[] { name });
return Integer.toString(cmdId[0]);
}
}