【问题标题】:KPL commands with zebra and JAVA带有斑马和 JAVA 的 KPL 命令
【发布时间】:2018-05-04 15:23:04
【问题描述】:

我尝试打印到打印机 Zebra 型号 KR203,这些打印机使用语言 KPL(Kiosk 打印机语言),正确打印测试页销售但我的代码停留在:“正在打印...”。

目前我正在做这个非常简单的代码:

PrintService printService = PrintServiceLookup.lookupDefaultPrintService();
PrintRequestAttributeSet attributeSet = new HashPrintRequestAttributeSet();

我的默认打印机是斑马

System.out.println("Default Printer :" + printService);
String kplcommand = "<ESC>P<N1>"; // In this line try print test page            
byte[] by = kplcommand .getBytes();
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
Doc doc = new SimpleDoc(by, flavor, null);
DocPrintJob job = printService.createPrintJob();
 try {
        job.print(doc, null); 
        //job.print(doc, attributeSet);
    } catch (PrintException e) {
        System.out.println("e " + e);
    }

帮助,我无法得出结论 注意:我正在使用 Java 桌面

【问题讨论】:

    标签: java printing zebra-printers


    【解决方案1】:

    我认为有必要使用 kpl 命令稍后通过尝试和失败打印我可以使用这些行进行打印:

    public void PrintTicketZ() {        
        PrintRequestAttributeSet attributeSet = new HashPrintRequestAttributeSet();
        attributeSet.add(OrientationRequested.PORTRAIT);
        attributeSet.add(new Copies(1));
        attributeSet.add(new JobName("PrintService", null));
        attributeSet.add(new MediaPrintableArea(10, 0, 60, 400, MediaPrintableArea.MM));
    
        PrinterJob pj = PrinterJob.getPrinterJob();
        pj.setPrintable(new Printable() {
            public int print(Graphics g, PageFormat pf, int pageIndex) {
                if (pageIndex == 0) {
                    int h = 100;
                    int w = 100;
                    String company="--";                      
                    try {
                        double x = pf.getImageableX();
                        double y = pf.getImageableY();
                        Paper paper = pf.getPaper();
                        pf.getPaper().setImageableArea(0, 0, paper.getWidth(), paper.getHeight());
                        Graphics2D g2d = (Graphics2D) g;
                        g2d.translate(x, y);
                        g2d.setColor(Color.black);
                        g2d.setFont(new Font("TimesRoman", Font.PLAIN, 10));
                        g2d.drawString("FOLIO: ", 105, 40);
                        g2d.drawString("FECHA: ", 0, 60);
                        g2d.drawString("HORA: ", 0, 75);
                        g2d.drawString("N° EMPLEADO: " , 0, 100);
                        g2d.drawString("EMPRESA: " , 0, 115);
                        g2d.drawString("EMPLEADO: ", 0, 130);   
                    } catch (WriterException e) {
                        System.out.println("Error " + e);
                    }
                    return Printable.PAGE_EXISTS;
                } else {
                    return Printable.NO_SUCH_PAGE;
                }
            }
        });
    
        PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService();
        if (defaultPrintService != null) {
            try{
                String print_default = defaultPrintService.getName();
                pj.setPrintService(defaultPrintService);
                pj.print(attributeSet);
                log.info("Printing...");
    
                PrintServiceAttributeSet printServiceAttributeSet = defaultPrintService.getAttributes();
                String trabajo = printServiceAttributeSet.get(QueuedJobCount.class).toString();
                int trabajos = Integer.parseInt(trabajo);
    
            } catch (PrinterException pe) {
                log.error("Error al imprimir: " + pe);
                System.out.println(pe);
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-04
      • 1970-01-01
      • 2014-04-09
      相关资源
      最近更新 更多