通过Java脚本直接将zpl数据内容打印到打印机

时间:2018-07-26 01:16:12

标签: printing

我正在尝试打印将标签打印到斑马打印机的ZPL格式(斑马打印机代码)的数据。我想通过Java脚本将内容打印到zebra打印机。我正在从传递ZPL数据的ERP系统中调用Java程序。当前所有代码执行完后,什么也不会打印。 任何输入将不胜感激。

下面是我的代码。 。     导入java.util.Date;     导入java.util.Properties;

import javax.print.PrintServiceLookup;

import oracle.e1.bssvfoundation.base.BusinessService;
import oracle.e1.bssvfoundation.base.IContext;
import oracle.e1.bssvfoundation.base.TestBusinessService;
import oracle.e1.bssvfoundation.connection.IConnection;
import oracle.e1.bssvfoundation.exception.BusinessServiceException;
import oracle.e1.bssvfoundation.util.E1Message;
import oracle.e1.bssvfoundation.util.E1MessageList;

 public abstract class GetMediaObj1 extends BusinessService {

public static E1MessageList getMediaObject1(IContext context, 
IConnection      connection, GetMediaObj_VO internalVO) {


    startInternalMethod(context, "getMediaObject1", internalVO);
    E1MessageList messages = new E1MessageList();
    context.getBSSVLogger().app(context, "Beginning of BSSV");


    try {
        poll (internalVO); 
    }
    catch(Exception e){
       String substitutionString = e.getStackTrace()[0].getClassName() + "." 
+ e.getStackTrace()[0].getMethodName() + "|" + e.getMessage();

       E1Message msg = new E1Message(context, "003FIS", substitutionString);
       messages.addMessage(msg);

       context.getBSSVLogger().app(context,msg.getCallObjError
().getGlossaryText(),null,null,e);
       System.out.println(msg.getCallObjError().getGlossaryText());
    }


     finishInternalMethod(context, "getMediaObject1");

     return messages;
}

public static void poll(GetMediaObj_VO internalVO){             //主要工作方法

        String 

        //ZPL data
        File f = new File(internalVO.getSzAdditionalText());

        both = f+".txt";
        String files;
        String printerName = null;

      //  boolean isPDF = false;
       // boolean isTXT = false;

      //name of the printer
        printerName = internalVO.getSzMediaDescription();


                       //         isPDF = f.getName().endsWith(".pdf");
                       //         isTXT = f.getName().endsWith(".txt");
                       //         System.out.println(sdf.format(new Date()) 
+ " " + f.getName());

                                try {
                                               FileOutputStream fos = null;
                                                PrintStream ps = null;
                                   // 
PrintServiceLookup.lookupDefaultPrintService();


                                                          fos = new FileOutputStream(printerName);
                                                        //     fos = new FileOutputStream(both);
                                                                ps = new PrintStream(fos);
                                                                ps.print(f);

                                                                ps.close();


                                } 
                                catch (IOException e) {
                                        System.out.println("IOException: "+e.toString());                                               
                                } catch (Exception e) {
                                        e.printStackTrace();

                                }


}

public static void main(String[] args) throws BusinessServiceException {
     try {
         //Call required before running a test harness using application (main()).
         TestBusinessService.startTest();
         //TODO:  call test methods
         TestBusinessService.callBSSVWithXMLFile("com.dt.bssv.J55MEDIA.GetMediaObj1",
                                                 "getMediaObject1",
                                                 "C:\\E910\\DV910\\java\\source\\com\\dt\\bssv\\J55MEDIA\\valueobject\\GetMediaObj_VO.xml",
                                                 false);

     } finally {
         //Call required after test is complete.  Needed to clean up daemon threads.
         TestBusinessService.finishTest();
     }
}

}

注释:我在f字段中有ZPL数据,并期待PrintStream将打印到打印机,但不会打印出来?

0 个答案:

没有答案