0

I am a complete newbie to kiosk printers.

I need to send a string from a java app to a zebra kr203 kiosk printer.

The machine is hooked up to a windows 7 pc and its drivers are installed. Printing test pages works fine.

I have also installed the setup utilities for the printer and they allow sending commands to it through EPL2 language. Again, I am completeley new to EPL2 but I have tried some example commands and nothing worked.

Can someone please write some basic java code to send a short string to the printer?

No GUI needed just a simple command line app.

EDIT: I found some code on google that gets the correct printService but it still won't print anything out.

EDIT NO. 2: I ended up using the Zebra SDK provided on their website. They keep code examples there which you can easily find by googling. I edited out the old code since it is useless.

Using the SDK and examples I figured out that the printer actually uses ZPL2 instead of EPL as I originally thought.

The SDK has its own API for sending commands at it works quite smoothly for me.

isaric
  • 195
  • 3
  • 18

2 Answers2

1

This is what I ended up using:

String defaultPrinter = PrintServiceLookup.lookupDefaultPrintService().getName();
com.zebra.sdk.comm.Connection myconnection = new com.zebra.sdk.comm.DriverPrinterConnection(defaultPrinter,1000,1000);
myconnection.open();
com.zebra.sdk.printer.ZebraPrinter myprinter = ZebraPrinterFactory.getInstance(myconnection);
String command = "^XA\n" +
                    "^FO50,50\n" +
                    "^A@N,20,20,E:TT0003M_.FNT\n" +
                    "^FDUplatili ste XXXX na račun XXXXXXXXXX^FS\n" +
                    "^FO50,150\n" +
                    "^A0,32,25\n" +
                    "^FD"+ date.toString()+ "^FS\n" +
                    "^FO50,250\n" +
                    "^A0,32,25^FDSlavnoska Avenija 19, 10000 Zagreb^FS\n" +
                    "^XZ";
myprinter.sendCommand(command);
myconnection.close();
isaric
  • 195
  • 3
  • 18
  • I have copy and paste your code but I get this error "Error en la con com.zebra.sdk.comm.UsbNativeCodeConnectionException: The native code dll is not loaded." Could you please help me?? – Omar Barrera Valentin Jan 09 '18 at 00:01
0

Do you have multiple printers to choose from...or just one printer?

    private void printLabel() {
        try{
            FileOutputStream fos = new FileOutputStream("\\Your Printer Here");
            PrintStream ps = new PrintStream(fos);

            //try with the EPL commands or take a look at the ZPL programming guide
            String commands = "N\n" +
                    "A50,50,0,2,2,2,N,\"" + label + "\"\n" +
                    "B50,100,0,1,2,2,170,B,\"" + label + "\"\n" +
                    "A50,310,0,3,1,1,N,\"" + czas + "\"\n" +
                    "P1\n";

            ps.println(commands);
            ps.print("\f");
            ps.flush();
            ps.close();

    }catch(Exception e){
        e.printStackTrace();
    }

} `

born2bmild
  • 134
  • 9
  • I have multiple printers with the Zebra set to default. Also, System.out.println("Default printer: " + defaultPrinter); returns Zebra. – isaric Apr 07 '15 at 13:03
  • @user3779674 Just curious - I wrote a program that used ZPL but I only needed to use one printer so I harded-coded the path in FileOutputStream, Would post that if you like but it is probably of no use to you. I also could've helped a little with ZPL..not so much with EPL(sorry) – born2bmild Apr 07 '15 at 13:16
  • @born2bmild The printer should support ZPL. Please post your code and I will give it a try. I can remove all the other printers to give it a go. It's just an office test, nothing critical. – isaric Apr 07 '15 at 13:47
  • @user3779674 Hope it works for you. You may want to fiddle with the x,y coordinates and dpi. That's what I had to do with ZPL, when I changed printers...That's all I have until much later – born2bmild Apr 07 '15 at 14:48
  • @born2bmild what is czas? – isaric Apr 08 '15 at 13:41