1

我正在尝试将打印机作业语言命令发送到 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 
4

1 回答 1

1

如此处所述,您似乎缺少关闭的“通用退出语言”命令 (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 命令语法是否有问题,但作为参考, 这对我有用

于 2019-04-21T05:08:02.747 回答