How to Print Unsupported Character Sets with a POS Printer

From wizarPOS

The printer of the POS support GB2312 character set by default, and it also support some Latin character codepage (ISO8859-1,...). Developer can use ESC command to change the codepage. please refer to here: http://sdkwiki.wizarpos.com/index.php/ESC_Commands#ESC_t Be aware, that not all the codepage in the ESC command are supported in all of our POS model. some old POS model only support ISO8859-1 and GB2312.

If you find the above information still can not make you print correct character, or you want more beautiful font, you can try to use HTML content printing. These section will tell you how to print receipt by HTML.

Please add WebView.enableSlowWholeDocumentDraw() in your APP source code, because we use android WebView to print html content.

Permission

The app declares the android.permission.SYSTEM_ALERT_WINDOW in the manifest. This is required by printHTML utility to use a hidden HTML rendering window.

By Java API

Please refer to java API Spec. Download APIDemo from [Java Samples], there is a printHtml method in com.wizarpos.apidemo.action.PrinterAction.java, you can call it like this:

public void printHtml(final Map<String, Object> param, final ActionCallback callback) {
        try {
            final String htmlContent = "<!DOCTYPE html>" +
                    "<html>" +
                    "<head>" +
                    "    <style type=\"text/css\">" +
                    "     * {" +
                    "        margin:0;" +
                    "        padding:0;" +
                    "     }" +
                    "    </style>" +
                    "</head>" +
                    "<body>" +
                    "Demo receipts<br />" +
                    "MERCHANT COPY<br />" +
                    "<hr/>" +
                    "MERCHANT NAME<br />" +
                    "SHXXXXXXCo.,LTD.<br />" +
                    "530310041315039<br />" +
                    "TERMINAL NO<br />" +
                    "50000045<br />" +
                    "OPERATOR<br />" +
                    "50000045<br />" +
                    "<hr />" +
                    "CARD NO<br />" +
                    "623020xxxxxx3994 I<br />" +
                    "ISSUER ACQUIRER<br />" +
                    "<br />" +
                    "TRANS TYPE<br />" +
                    "PAY SALE<br />" +
                    "PAY SALE<br />" +
                    "<hr/>" +
                    "DATE/TIME EXP DATE<br />" +
                    "2005/01/21 16:52:32 2099/12<br />" +
                    "REF NO BATCH NO<br />" +
                    "165232857468 000001<br />" +
                    "VOUCHER AUTH NO<br />" +
                    "000042<br />" +
                    "AMOUT:<br />" +
                    "RMB:0.01<br />" +
                    "<hr/>" +
                    "BEIZHU<br />" +
                    "SCN:01<br />" +
                    "UMPR NUM:4F682D56<br />" +
                    "TC:EF789E918A548668<br />" +
                    "TUR:008004E000<br />" +
                    "AID:A000000333010101<br />" +
                    "TSI:F800<br />" +
                    "ATC:0440<br />" +
                    "APPLAB:PBOC DEBIT<br />" +
                    "APPNAME:PBOC DEBIT<br />" +
                    "AIP:7C00<br />" +
                    "CUMR:020300<br />" +
                    "IAD:07010103602002010A01000000000005DD79CB<br />" +
                    "TermCap:EOE1C8<br />" +
                    "CARD HOLDER SIGNATURE<br />" +
                    "I ACKNOWLEDGE SATISFACTORY RECEIPT OF RELATIVE GOODS/SERVICE<br />" +
                    "I ACKNOWLEDGE SATISFACTORY RECEIPT OF RELATIVE GOODS/SERVICE<br />" +
                    "I ACKNOWLEDGE SATISFACTORY RECEIPT OF RELATIVE GOODS/SERVICE<br />" +
                    "<br />" +
                    "Demo receipts,do not sign!<br />" +
                    "<br />" +
                    "<br />" +
                    "<br />" +
                    "</body>" +
                    "</html>";
            new Handler(Looper.getMainLooper()).post(new Runnable() {
                @Override
                public void run() {
                    try {
                        device.printHTML(mContext, htmlContent, null);
                        sendSuccessLog(mContext.getString(R.string.operation_succeed));
                    } catch (Exception e) {
                        sendFailedLog(mContext.getString(R.string.operation_failed));
                    }
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
            sendFailedLog(mContext.getString(R.string.operation_failed));
        }
    }

By JNI API

API Overview

PrintHtmlInterface.printHTML

void printHTML(Context context, String htmlcontent, PrinterHtmlListener listener);

Print HTML content.

Returns
context Context : The activity or application context of the APP. It's used by method to create the hidden window.
htmlcontent String : The HTML content for printing.
listener PrinterHtmlListener : the callback listener to process the print result, Not null.

PrintHtmlInterface.convert2Image

void convert2Image(Context context, String htmlContent, PrinterHtmlListener listener);

Convert the html content to a image, if want print, please call print API of the printer.

Returns
context Context : The activity or application context of the APP, Not null.
htmlcontent String : The html content, Not null.
listener PrinterHtmlListener : the callback listener to process the print result, Not null.

PrinterHtmlListener.onGet

void onGet(Bitmap returbitmap, int result);

This callback will return the bitmap if you invoke the convert2Image method of the PrintHtmlInterface.

Returns
returbitmap Bitmap : The returned bitmap.
result int: The result of get image, "2:" BITMAP_ERROR, "3:" BITMAP_SUCCESS.

PrinterHtmlListener.onFinishPrinting

void onFinishPrinting(int result);

This callback will be callled after printing if you invoke the printHTML method of the PrintHtmlInterface.

Returns
result int : The result of the print,"0:" PRINT_ERROR, "1:" PRINT_SUCCESS,"2:" BITMAP_ERROR, "3:" BITMAP_SUCCESS,"4:" DEVICE_NOT_OPEN.

Sample

Please find the sample in SDK folder, apidemo