0
private void sendZPLContentToPrinter(String ipAddress, int portNumber, String zplContent) throws IOException {
    try (Socket socket = new Socket()) {
        socket.setSoTimeout(DEFAULT_CONNECTION_TIMEOUT);
        socket.connect(new InetSocketAddress(ipAddress, portNumber), DEFAULT_CONNECTION_TIMEOUT);
        OutputStream outputStream = socket.getOutputStream();
        byte[] zplBytes = zplContent.getBytes("UTF-8");
        outputStream.write(zplBytes);
        outputStream.flush();

    } catch (SocketTimeoutException e) {
        throw new IOException("Connection timed out while trying to connect to the printer.");
    }
}

the above code will print the content. now i want to know the printer job if it is successfull or not

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
Aravind A
  • 1
  • 1

1 Answers1

0

Assuming that you are using the Zebra SDK for Java, there is an example in the javadocs. (Copied here in case the link evaporates.)

package test.zebra.sdk.printer.examples;
 
 import com.zebra.sdk.comm.Connection;
 import com.zebra.sdk.comm.ConnectionException;
 import com.zebra.sdk.comm.TcpConnection;
 import com.zebra.sdk.printer.PrinterStatus;
 import com.zebra.sdk.printer.ZebraPrinter;
 import com.zebra.sdk.printer.ZebraPrinterFactory;
 import com.zebra.sdk.printer.ZebraPrinterLanguageUnknownException;
 
 public class PrinterStatusExample {
 
     public static void main(String[] args) throws Exception {
         Connection connection = new TcpConnection("192.168.1.100", TcpConnection.DEFAULT_ZPL_TCP_PORT);
         try {
             connection.open();
             ZebraPrinter printer = ZebraPrinterFactory.getInstance(connection);
 
             PrinterStatus printerStatus = printer.getCurrentStatus();
             if (printerStatus.isReadyToPrint) {
                 System.out.println("Ready To Print");
             } else if (printerStatus.isPaused) {
                 System.out.println("Cannot Print because the printer is paused.");
             } else if (printerStatus.isHeadOpen) {
                 System.out.println("Cannot Print because the printer head is open.");
             } else if (printerStatus.isPaperOut) {
                 System.out.println("Cannot Print because the paper is out.");
             } else {
                 System.out.println("Cannot Print.");
             }
         } catch (ConnectionException e) {
             e.printStackTrace();
         } catch (ZebraPrinterLanguageUnknownException e) {
             e.printStackTrace();
         } finally {
             connection.close();
         }
     }
 }

The code is self-explanatory.

For information on performing other tasks, take a look at the javadocs' overview page.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • outputStream.write(zplBytes); the above line will issue the print, just after that i want to find it the print job is successful or not – Aravind A Aug 15 '23 at 00:58
  • do i need to add any dependency – Aravind A Aug 15 '23 at 01:09
  • 1) Look at the javadocs to see if there is a way to get exactly what you want. Otherwise, adapt the above code. 2) Read the overview page. Basically yes ... though I didn't read to see if they have mavenized it. – Stephen C Aug 15 '23 at 01:17
  • can i download the jar from somewhere? – Aravind A Aug 15 '23 at 01:21
  • i have downloaded the jar from git hub and added it in my project – Aravind A Aug 15 '23 at 02:13
  • Aravind: research first, and again. Then ask. – Stephen C Aug 15 '23 at 03:17
  • the project is working fine after add the jar in my project but after generate the jar, i tried to run it via cmd but some exception is coming what should i do – Aravind A Aug 16 '23 at 05:05
  • You haven't provided any information that would help us to help you. So, I will just point you at [How to debug small programs](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) ... so that you can learn to help yourself. – Stephen C Aug 16 '23 at 05:36
  • your.groupId external-library 2.11.2800 system ${project.basedir}/src/main/resources/ZSDK_API.jar jar true [ERROR] 'dependencies.dependency.systemPath' for your.groupId:external-library:jar must specify an absolute path but is ${project.basedir}/src/main/resources/ZSDK_API.jar @ line 77, column 25 – Aravind A Aug 16 '23 at 08:14