Skip to content

Instantly share code, notes, and snippets.

@kaueDM
Created November 11, 2017 17:43
Show Gist options
  • Save kaueDM/8e07ccc482a2c7cbbe635fb6eae82531 to your computer and use it in GitHub Desktop.
Save kaueDM/8e07ccc482a2c7cbbe635fb6eae82531 to your computer and use it in GitHub Desktop.
public void printTickets(String ticketsArray, Promise promise) throws JSONException {
JSONArray tickets = new JSONArray(ticketsArray);
for (int i = 0; i < tickets.length(); i++) {
JSONObject ticket = tickets.getJSONObject(i);
String productName = ticket.getString("productName");
String ticketUID = ticket.getString("ticketUID");
try {
commands.initialize();
commands.fontSize(14);
commands.alignCenter("Nome do Evento").lineFeed(1);
commands.fontSize(18).alignCenter(productName).lineFeed(1);
commands.fontSize(14);
commands.qrCode(ticketUID).lineFeed(5).partialCut();
}catch( IOException e) {
promise.reject(COMMAND_ERROR, e);
}
catch (OutOfRangeException e) {
promise.reject(OUT_OF_RANGE, e);
}
}
try{
//final cut
commands.lineFeed(8);
commands.fullCut();
ByteArrayOutputStream generator = new ByteArrayOutputStream();
generator.write(commands.getByteArray());
printer.openPrinterConnection(getReactApplicationContext(), ThermalPrinterModule.this, ThermalPrinterModule.this);
printer.print(generator.toByteArray());
printer.closePrinter();
promise.resolve("Impressão Concluída");
}catch( IOException e) {
promise.reject(PRINT_ERROR, e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment