1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
//INIT Printer
POSPrinterControl19 ptr = (POSPrinterControl19) new POSPrinter();
try {
//Open the device.
//Use the name of the device that connected with your computer.
ptr.open("POSPrinter");
//Get the exclusive control right for the opened device.
//Then the device is disable from other application.
ptr.claim(1000);
//Enable the device.
ptr.setDeviceEnabled(true);
// PRINT
// head
ptr.printNormal(POSPrinterConst.PTR_S_RECEIPT, "\u001b|bC\u001b|2C\u001b|cAMyCompany\u001b|N\n");
// Print address
// ESC|N = Normal char
ptr.printNormal(POSPrinterConst.PTR_S_RECEIPT, "\u001b|N212A My address \n");
//Print info
// ESC|rA = Right side char
// ESC|cA = Center side char
ptr.printNormal(POSPrinterConst.PTR_S_RECEIPT, "\u001b|cAOther informations \n\n\n");
//Print the total cost
// ESC|bC = Bold
// ESC|uC = Underline
// ESC|2C = Wide charcter
ptr.printNormal(POSPrinterConst.PTR_S_RECEIPT, "\u001b|uC \u001b|N\n");
ptr.printNormal(POSPrinterConst.PTR_S_RECEIPT, "\u001b|bC\u001b|2CTotal " + Utils.formatTo2Digits(total-vente.getMontantReduction()) + "\u001b|N\n");
if (paymentType.equals(ConstantsUtils.PAYMENT_CASH)) {
ptr.printNormal(POSPrinterConst.PTR_S_RECEIPT, "Argent client " + remisTextField.getText() + "\n");
ptr.printNormal(POSPrinterConst.PTR_S_RECEIPT, "Remis " + remettreTextField.getText() + "\n\n");
} else {
ptr.printNormal(POSPrinterConst.PTR_S_RECEIPT, "Paiement bancontact.\n\n");
}
ptr.printNormal(POSPrinterConst.PTR_S_RECEIPT, "\u001b|cAEchange sous 7 jours\n");
ptr.printNormal(POSPrinterConst.PTR_S_RECEIPT, "\u001b|cAExchange under 7 days\n\n");
//Print date
// ESC|cA = Centaring char
ptr.printNormal(POSPrinterConst.PTR_S_RECEIPT, "\u001b|cA" + time + "\n\n");
// JavaPOS's code for Step4
//Barcode printing
if (ptr.getCapRecBarCode() == true) {
ptr.printBarCode(POSPrinterConst.PTR_S_RECEIPT, bcData, POSPrinterConst.PTR_BCS_JAN13,
30, ptr.getRecLineWidth(), POSPrinterConst.PTR_BC_CENTER,
POSPrinterConst.PTR_BC_TEXT_BELOW);
}
//Feed the receipt to the cutter position automatically, and cut.
// ESC|#fP = Line Feed and Paper cut
ptr.printNormal(POSPrinterConst.PTR_S_RECEIPT, "\u001b|fP");
//Cancel the device.
ptr.setDeviceEnabled(false);
//Release the device exclusive control right.
ptr.release();
//Finish using the device.
ptr.close();
} catch (JposException ex) {
ex.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}
finally{
this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
try {
//Finish using the device.
ptr.close();
} catch (JposException ex1) {
ex1.printStackTrace();
}
} |
Partager