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);
}
}
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.
Points: 1
You voted ‘up’
Hi Samantha, thanks for your answer I have update: "String kplcommand = "<ESC>P<N1>" by
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
Points: 0
You voted ‘up’
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
Points: 1
You voted ‘up’
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);
}
}
}
Points: 0
You voted ‘up’
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
Points: 0
You voted ‘up’
Points: 1
You voted ‘up’