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

用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博客 ” ,链接:http://blog.itpub.net/93029/viewspace-1027376/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/93029/viewspace-1027376/

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值