We have a live app on Clover App Market. So far I was using the below code to print the receipt i.e
String PrintData = getPrintData(card_number.getText().toString(), valueaddedamount.getText().toString(), availablebalanceamount.getText().toString(), TransactionID);
//Toast.makeText(GiftPayment_Sucessful.this, PrintData, Toast.LENGTH_SHORT).show();
TextPrintJob tb = new TextPrintJob.Builder().text(PrintData).build();
tb.print(GiftPayment_Sucessful.this, account);
/** * prepare print data * * @param cardnumber last four digit of processed card * @param valueaddedamount transaction amount * @param availablebalanceamount available balance of Gift Card * @param transactionId current transaction id * @return prepare the text data for the printing receipt of transaction and return formatted text */ public String getPrintData(String cardnumber, String valueaddedamount, String availablebalanceamount, String transactionId) {
String seperator = "\t\t\t\t\t\t";
String maskedCardNo = "***********" + cardnumber.substring(cardnumber.length() - 4);
//String printstring = "\n\n\n"+"\t\t\t\t"+merchantName+"\n"+"\t\t\t\t"+merchantAdress+"\n\n\n"+"\t\t"+"Cashier:"+employeeName+"\n"+"\t\t"+currentDate+"\n\n\n";
String printstring = "\n\n\n" + "\t\t\t\t\t" + "eGiftSolutions Gift Receipt" + "\n\n\n\n" + "\t\t" + "Merchant : " + merchantName + "\n" + "" + "\t\t" + "Cashier: " + employeeName + "\n" + "\t\t" + currentDate + "\n\n\n";
switch (Constant.transaction_mode) {
case addValue:
printstring = printstring + card_number + "\tfrom\t" + maskedCardNo + "\n" + "$ " + valueaddedamount + "\nNew Card Balance \t" + "$ " + availablebalanceamount;
break;
case balanceEnquiry:
//printstring = printstring+card_number + "\tfrom\t" + maskedCardNo + "\nBalance \t" + "$ " + availablebalanceamount;
printstring = printstring
+ "\t\tCard No" + seperator + maskedCardNo
+ "\n" + "\n" + "\t\t" + Constant.getRightAlignedAmountString("Card Balance", "$ " + getPrecesion(availablebalanceamount))
+ "\n\n" + "\t\t" + "eGift Trans ID: " + seperator + transactionId;
break;
case balanceTransfer:
printstring = printstring + card_number + "\tfrom\t" + maskedCardNo + "\nBalance \t" + "$ " + availablebalanceamount;
break;
case cardActivate:
printstring = printstring + card_number + "\t - " + maskedCardNo + "\nBalance \t" + "$ " + availablebalanceamount;
break;
case cardDeactivate:
printstring = printstring + card_number + "\t - " + maskedCardNo + "\n ";
break;
}
// printstring = printstring + "\n\n"+"\t\t"+"Thank You COME AGAIN!"+"\n\n";
printstring = printstring + "\n\n" + "\t\t\t\t\t\t\t\t\t\t" + "Thank You!" + "\n" + "\t\t\t\t\t\t\t\t" + "PLEASE COME AGAIN!" + "\n\n";
printstring = printstring + "\t\t\t\t\t\t\t\t" + "Check Card Balance at" + "\n" + "\t\t\t\t\t\t" + "http://www.cardbalance.info" + "\n\n" + ".";
//Log.d("Print Receipt---", printstring);
// Toast.makeText(GiftPayment_Sucessful.this, printstring, Toast.LENGTH_LONG).show();
return printstring;
}
The above code prints the receipt but its not well structured mainly in terms of alignment. Hence we tried using View Print Job with below line of code ie.
TextView view = new TextView(this); view.setText(PrintData);
// on button click new ViewPrintJob.Builder().view(view).build().print(GiftActivateMultiple.this, mAccount);
the above line of code gives error on status bar stating "Error in printing".
So can you please help me with sample example for ViewPrintJob or let me know what is the exact error and how it can be resolved if ViewPrintJob.
Any help will be truly appreciated.