我试图发送打印机作业语言命令到惠普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 发布于 2019-04-21 05:08:02
正如注意到的here,您似乎缺少了关闭 'Universal‘命令(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。
https://stackoverflow.com/questions/51031035
复制相似问题