我在取消打印作业时遇到问题,我可以在使用这样的 java 执行打印方法后打印成功
public static void print(byte[] bytes, String jobName, String printerIpAdd, Integer printerPort, String trayNumber) {
System.out.println("port " + printerPort);
try (Socket socket = new Socket(printerIpAdd, printerPort)) {
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
System.out.println("bytes[] = " + bytes.length);
out.write(27); //esc
out.write("%-12345X@PJL\n".getBytes());
out.write(("@PJL SET JOBNAME=" + jobName + "\n").getBytes());
out.write(("@PJL SET LPAPERSOURCE=TRAY" + trayNumber + "\n").getBytes());
out.writeBytes("@PJL SET PALETTESOURCE = DEVICE\n");
out.write(("@PJL SET PAPER=A5\n").getBytes());
out.write(("@PJL SET COPIES=1"\n").getBytes());
out.write("@PJL ENTER LANGUAGE=PDF\n".getBytes());
out.write(bytes); //data
out.write(27); //esc
out.write("%-12345X@PJL\n".getBytes());
out.flush();
out.close();
} catch (IOException ex) {
LOGGER.error(ex);
}
}
当打印机中没有纸或打开盖子或托盘被移除时出现问题,打印作业已挂起,因此我需要取消打印机的先前订单。所以我正在尝试使用此代码但不与我合作并创建另一个打印作业而不是取消
public static void cancelPrintJob(String jobName, String printerIpAdd, Integer printerPort) {
System.out.println("port " + printerPort);
try (Socket socket = new Socket(printerIpAdd, printerPort)) {
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
/*
<ESC>%-12345X@PJL <CR><LF>
@PJL DEFAULT JOBID =ON <CR><LF>
@PJL USTATUS JOB = ON <CR><LF>
@PJL JOB <CR><LF>
<ESC>%-12345X@PJL <CR><LF>
@PJL ENTER LANGUAGE = PCL <CR><LF>
<ESC>E...PCLJob.!!!JobCancel !
@PJL EOJ <CR><LF>
<ESC>%-12345X
*/
out.write(27); //esc
out.write("%-12345X@PJL\r\n".getBytes());
out.write(("DEFAULT JOBID =ON\r\n").getBytes());
out.write(("@PJL USTATUS JOB = ON\r\n").getBytes());
out.write(("@PJL JOB\r\n").getBytes());
out.write(27); //esc
out.write("%-12345X@PJL\\rn".getBytes());
out.write("@PJL ENTER LANGUAGE = PCL\r\n".getBytes());
out.write(27); //esc
out.write(("@PJL EOJ NAME =" + jobName + "\r\n").getBytes());
out.write(27); //esc
out.write("%-12345X@PJL\n".getBytes());
out.flush();
out.close();
} catch (IOException ex) {
LOGGER.error(ex);
}
}