Hello World, using printer KR203 and JAVA

Hi, I try to send a Hello World to a thermal printer Zebra model KR203, these printers use the language KPL (Kiosk Printer Language), when printing a test page sale correctly but with my code stays in: "Printing ...", I can´t use the link-os-sdk because is not compatible with these type of printers this is my code:

 

    public void Print() {

        PrintService printService = PrintServiceLookup.lookupDefaultPrintService(); //Here ZEBRA KR203 Is default printer

        PrintRequestAttributeSet attributeSet = new HashPrintRequestAttributeSet();

        System.out.println("Default Printer :" + printService);

        String kplcommand = "<ESC>P<N1>\r\n"; // In this line try print test page

        byte[] by = kplcommand .getBytes();

        DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;

        Doc doc = new SimpleDoc(by, flavor, null);

        DocPrintJob job = printService.createPrintJob();

        try {

            job.print(doc, null);

            //job.print(doc, attributeSet);

        } catch (PrintException e) {

            System.out.println("e " + e);

        }

    }

Samantha Corn
Hi Omar,I believe it may not

Hi Omar,

I believe it may not be printing because your KPL isn't correct. There should be a number instead of N1 in "<ESC>P<N1>\r\n". The KR203 Programming Guide contains the following table with possible values for N1.

Vote: 
Vote up!
Vote down!

Points: 1

You voted ‘up’


Omar Barrera
Hi Samantha, thanks for your

Hi Samantha, thanks for your answer I have update: "String kplcommand = "<ESC>P<N1>" by

  • String kplcommand = "<ESC>P<0>\r\n";
  • String kplcommand = "<ESC>P<0>";

But nothing was printed, here​ I found that it is necessary to convert the code to hexadecimal format but I do not know what its equivalence is. Could you please help me please

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Manuel Caicedo-...
Hi Omar,The KR203 is a

Hi Omar,

The KR203 is a strictly graphics printer and need to be used with the KR203 Windows driver found on our Website, so it will not work with these commands if you are not using the driver, or the toolbox associated with it, please, check the link below for available resources.

KR203 Kiosk Printer Support & Downloads | Zebra

Thanks,

MC

Vote: 
Vote up!
Vote down!

Points: 1

You voted ‘up’


Omar Barrera
Thanks for your answer, the

Thanks for your answer, the main idea is to print using the java language not the toolbox, first I thought it was necessary to use the kpl commands to print later by try and failure I could print using these lines:

    public void PrintTicketZ() {       

        PrintRequestAttributeSet attributeSet = new HashPrintRequestAttributeSet();

attributeSet.add(OrientationRequested.PORTRAIT);

        attributeSet.add(new Copies(1));

        attributeSet.add(new JobName("PrintService", null));

        attributeSet.add(new MediaPrintableArea(10, 0, 60, 400, MediaPrintableArea.MM));

PrinterJob pj = PrinterJob.getPrinterJob();

        pj.setPrintable(new Printable() {

            public int print(Graphics g, PageFormat pf, int pageIndex) {

            if (pageIndex == 0) {

                    int h = 100;

                    int w = 100;

                String company="--";             

                    try {

                        double x = pf.getImageableX();

                        double y = pf.getImageableY();

                        Paper paper = pf.getPaper();

                        pf.getPaper().setImageableArea(0, 0, paper.getWidth(), paper.getHeight());

                        Graphics2D g2d = (Graphics2D) g;

                        g2d.translate(x, y);

                        g2d.setColor(Color.black);

                        g2d.setFont(new Font("TimesRoman", Font.PLAIN, 10));

                        g2d.drawString("FOLIO: ", 105, 40);

                        g2d.drawString("FECHA: ", 0, 60);

                        g2d.drawString("HORA: ", 0, 75);

                        g2d.drawString("N° EMPLEADO: " , 0, 100);

                        g2d.drawString("EMPRESA: " , 0, 115);

                        g2d.drawString("EMPLEADO: ", 0, 130);  

                    } catch (WriterException e) {

                        System.out.println("Error " + e);

                    }

                    return Printable.PAGE_EXISTS;

                } else {

                    return Printable.NO_SUCH_PAGE;

                }

            }

        });

PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService();

        if (defaultPrintService != null) {

            try{

String print_default = defaultPrintService.getName();

                pj.setPrintService(defaultPrintService);

                pj.print(attributeSet);

log.info("Printing...");

                           

                PrintServiceAttributeSet printServiceAttributeSet = defaultPrintService.getAttributes();

                String trabajo = printServiceAttributeSet.get(QueuedJobCount.class).toString();

                int trabajos = Integer.parseInt(trabajo);

            } catch (PrinterException pe) {

log.error("Error al imprimir: " + pe);

                System.out.println(pe);

            }

        }

    }

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Manuel Caicedo-...
Omar,The only format

Omar,

The only format supported is graphics by using this command format:

For the full explanation of the example, follow the link below, and go to page 53.

https://www.zebra.com/content/dam/zebra/manuals/en-us/printer/kr203-pm-en.pdf

I hope this works.

Thanks,

MC

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Omar Barrera
(No subject)

Vote: 
Vote up!
Vote down!

Points: 1

You voted ‘up’


Log in to post comments