【问题标题】:Using Java to send PJL commands to HP 4515 Printer使用 Java 向 HP 4515 打印机发送 PJL 命令
【发布时间】:2018-12-04 11:24:46
【问题描述】:

我正在尝试将打印机作业语言命令发送到 HP 4515 打印机。但是,打印机不打印任何内容。下面是我的代码。打印机位于远程,我只能请那里的人检查是否有任何打印出来。不幸的是,什么都没有打印出来。 PJL 命令是否格式不正确?如何使用 Java 和 PJL 获取作业状态?

  socket = new Socket("192.168.1.101", 9100);
        out = new DataOutputStream(socket.getOutputStream());
        DataInputStream input = new DataInputStream(socket.getInputStream());


        final char ESC = 0x1b;
        final String UNESCAPED_UEL  = "%-12345X";
        String UEL = ESC + UNESCAPED_UEL;
        out.writeBytes(UEL); 
        out.writeBytes("@PJL\r\n");

        //out.writeBytes("@PJL SET MEDIASOURCE = TRAY2\r\n"); //I tried this line of code as well
        out.writeBytes("@PJL SET PAPER = LETTER\r\n");

        out.writeBytes("@PJL ENTER LANGUAGE = PDF\r\n");
        for(int i=0; i<copies; i++) {
            out.write(ps, 0, ps.length); //ps is of type byte[]. It contains the content of PostScript file
        }
        out.flush();

打印机的纸张设置:

TRAY 1 SIZE 
TRAY 1 TYPE 
TRAY 2 SIZE LETTER
UNIT OF MEASURE 
X DIMENSION INCHES (5.83 - 8.5)
Y DIMENSION INCHES (8.27 - 14.0)
TRAY 2 TYPE 

【问题讨论】:

    标签: java java-print pjl


    【解决方案1】:

    here 所述,您似乎缺少关闭“通用退出语言”命令 (UEL)。在 PJL 中是必需的。它定义了任何基于 PJL 的数据流的开始和结束

    例如:

    socket = new Socket("192.168.1.101", 9100);
    out = new DataOutputStream(socket.getOutputStream());
    DataInputStream input = new DataInputStream(socket.getInputStream());
    
    
    final char ESC = 0x1b;
    final String UNESCAPED_UEL  = "%-12345X";
    String UEL = ESC + UNESCAPED_UEL;
    out.writeBytes(UEL); 
    out.writeBytes("@PJL\r\n");
    out.writeBytes("@PJL SET PAPER = LETTER\r\n");
    out.writeBytes("@PJL ENTER LANGUAGE = PDF\r\n");
    for(int i=0; i<copies; i++) {
        out.write(ps, 0, ps.length);
    }
    out.writeBytes(UEL); // <-- add this
    out.flush();
    

    我不知道你的 PJL 命令语法是否有问题,但供参考this is working for me

    【讨论】:

      猜你喜欢
      • 2019-01-27
      • 1970-01-01
      • 1970-01-01
      • 2016-04-28
      • 2018-07-08
      • 1970-01-01
      • 2014-08-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多