question

maninder avatar image
maninder asked Jeffrey Blattman commented

How to use View Print Job ?

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.

Print
8 comments
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jeffrey Blattman avatar image Jeffrey Blattman ♦♦ commented ·

If you are getting an error, please tell us what is the error. Start with the logcat around when the error occurs.

0 Likes 0 ·
maninder avatar image maninder commented ·

To be honest we are in jeopardy here as we writing the code and sharing with client as we dont have the clover device. So we build the apk and share with the client and when they run on clover device they have thats why they are telling us that they are getting this issue on status bar stating "Error in printing".

Is there a working exampe to implement print so that i can compare my ViewPrintJob code with the example ? Is there any printer dependency ? Any specific settings to be used ? There must be something to fix this up and get it going.

0 Likes 0 ·
Jeffrey Blattman avatar image Jeffrey Blattman ♦♦ commented ·

No, we don't have any examples of ViewPrintJob in our SDK. I re-looked at our usage, and there's no magic: use the builder to add the view and call print(). This can only target receipt printers, not order printers. Another thing you can try is to convert the TextView to a Bitmap yourself, and use ImagePrintJob. This at least would allow you to verify that the intermediate image is as you expect. You can also purchase a Star TSP100 printer for testing. We don't officially support this but there are drivers for it in our product so you could use it for your testing.

0 Likes 0 ·
maninder avatar image maninder commented ·

Thanks Jeff, I tried taking a relative layout and converting into bitmap and use ImagePrintJob for print but it prints the receipt with black background and white text which is very small. I assume it will match the printer configuration. So what is the best text size and alignment i can give to contents in relative layout for better printing and how to avoid black background ? Thanks in advance.

0 Likes 0 ·
maninder avatar image maninder commented ·

Here is the image Link for your reference @jeff, https://drive.google.com/file/d/0B5gL...

0 Likes 0 ·
Show more comments

0 Answers

Welcome to the
Clover Developer Community