使用 Java 将 PJL 命令发送到 HP 4515 打印机
Using Java to send PJL commands to HP 4515 Printer
我正在尝试将打印机作业语言命令发送到 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
如前所述 ,您似乎缺少 closing 'Universal Exit Language' 命令 (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。
我正在尝试将打印机作业语言命令发送到 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
如前所述
例如:
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。