ITPub博客

首页 > 应用开发 > IT综合 > 怎么用java调用用codesoft设计的条形码文档

怎么用java调用用codesoft设计的条形码文档

原创 IT综合 作者:terryisme 时间:2009-09-26 11:47:35 1 删除 编辑

用ireport设定的jasper有相应的代码来调用,如 JasperPrint print = JasperFillManager.fillReport()。但用ireport制作条形码不够精细。但用codesoft来设计的时候,我们怎么去调用生成的LAB文档,并打印出来。希望大虾指点一下。

经过好多天的努力自己终于将这个问题解决了。现在代码共享如下,仅供参考因为本人还不精通。

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

[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/93029/viewspace-1027376/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 备案
请登录后发表评论 登录
全部评论

注册时间:2009-02-23

  • 博文量
    142
  • 访问量
    632452