0

I have this Raw ESC/POS command for LX-300+, and i want to print it through Print Server using Socket.

String escp = " '\x1B' + '\x40', // initialize the printer, reset printer to defaults " +                                                                 
     " '\x1B' + '\x78' + '\x31', // Set Print Quality NLQ " +
     " '\x1B' + '\x6B' + '\x31', // Select typeface San serif " +
     " '\x1B' + '\x43' + '\x00' + '\x06', // set Page Length to 6 Inch " +
     " '\x1B' + '\x4D', // Select 12 cpi Spacing " +
     " '\x1B' + '\x45', // SET Bold Font ";

Question is, can we parse that String of escp with Socket? i use this code,

            Socket socket = null;
            OutputStream output = null;
            BufferedReader reader = null;
            
            try {
                socket = new Socket("10.0.5.30", 9100);
                socket.setSoTimeout(5000);
                output = socket.getOutputStream();
                reader = new BufferedReader(new java.io.InputStreamReader(socket.getInputStream()));
                
            } catch (UnknownHostException e) {
                // TODO: handle exception
            }
            
            if (socket != null && output != null) {
                try
                {                                       
                    output.write(escp.getBytes());
                    output.flush();
                    socket.shutdownOutput();
                
                    output.close();
                    socket.close();
                }
                catch (Exception e)
                {
                    System.out.println(e.toString());

                }
            }
  

The result is, printer LX-300 is not converting the ESC/POS Command. Just print the String inside escp variable. Any solution to this? i'm using linux 18.04 FYI.

Avian Driyanto
  • 93
  • 2
  • 11
  • 1
    Since the output data is defined as a character string, it will be in a normal state. If you want to output it as a control code, define it as a byte array as in this article. [How do I initialize a byte array in Java?](https://stackoverflow.com/q/11208479/9014308) Then the typeface san serif is \x01 instead of \x31. [EPSON ESC/P Reference Manual](http://www.dilwyn.me.uk/docs/printers/escp2ref.pdf) – kunif Sep 14 '20 at 12:07
  • How i defined that String escp into byte array, include with the text i want to print? i'm still don't get it how to do that. Let's try i want to print text "Just a Test" with BOLD. How do i defined that using byte array? – Avian Driyanto Sep 15 '20 at 04:52
  • 1
    For example, you can assemble the print contents by referring to this article [Dot Matrix BOLD Printing in Java](https://stackoverflow.com/q/32919623/9014308) and convert it to a byte array by referring to this article. [How to convert a Java String to an ASCII byte array?](https://stackoverflow.com/q/5688042/9014308) – kunif Sep 15 '20 at 05:18
  • @kunif i think i figure it out now. Many thanks from me. – Avian Driyanto Sep 15 '20 at 06:29

0 Answers0