How to Print Unsupported Character Sets with a POS Printer: Difference between revisions

From wizarPOS
(Replaced content with "{{Migrating|https://smartpossdk.gitbook.io/cloudpossdk/faq/printer/print-unsupported-character-sets}}")
Tag: Replaced
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
POS printer supports GB2312 character set by default and some Latin character sets (iso8859-1,...). Developers can use ESC commands to change character sets. See: http://sdkwiki.wizarpos.com/index.php/ESC_Commands#ESC_t
{{Migrating|https://smartpossdk.gitbook.io/cloudpossdk/faq/printer/print-unsupported-character-sets}}
 
If you find that the above information still does not allow you to print the correct characters, or if you want a more beautiful font, you can try printing with HTML content. This section will show you how to print receipts in HTML.
 
Add WebView.enableSlowWholeDocumentDraw() to the application source code because we use Android WebView to print HTML content.
 
== Permission ==
The application declares android.permission.SYSTEM_ALERT_WINDOW in the manifest. This is required for the printHTML utility to render windows using hidden HTML.
 
== '''Java SDK API''' ==
=== API Overview ===
==== printHTML ====
<syntaxhighlight lang="java">void printHTML(Context context, String htmlContent, PrinterHtmlListener listener) throws DeviceException;</syntaxhighlight >
Print html content, add WebView.enableSlowWholeDocumentDraw() in the calling app, and add this permission android.permission.SYSTEM_ALERT_WINDOW in manifest file.
{|class="wizarpostable"
|-
! scope="row" colspan="2" | Parameters
|-
| context || '''Context:''' context.
|-
| htmlContent || '''String:''' html content.
|-
| listener|| '''PrinterHtmlListener:''' PrinterHtmlListener.
|}
==== convertHTML2image ====
<syntaxhighlight lang="java">void convertHTML2image(Context context, String htmlContent, PrinterHtmlListener listener) throws DeviceException;</syntaxhighlight >
convertHTML2image, add WebView.enableSlowWholeDocumentDraw() in the calling app, and add this permission android.permission.SYSTEM_ALERT_WINDOW in manifest file.
{|class="wizarpostable"
|-
! scope="row" colspan="2" | Parameters
|-
| context || '''Context:''' context.
|-
| htmlContent || '''String:''' html content.
|-
| listener|| '''PrinterHtmlListener:''' PrinterHtmlListener.
|}
==== PrinterHtmlListener.onGet ====
<syntaxhighlight lang="java">void onGet(Bitmap bitmap, int errorCode);</syntaxhighlight>
{|class="wizarpostable"
|-
! scope="row" colspan="2" | Parameters
|-
| bitmap|| '''Bitmap :''' generated bitmap.
|-
| errorCode|| '''int:''' returned value:PRINT_ERROR = 0;PRINT_SUCCESS = 1;BITMAP_ERROR = 2;BITMAP_SUCCESS = 3;DEVICE_NOT_OPEN = 4.
|}
==== PrinterHtmlListener.onFinishPrinting ====
<syntaxhighlight lang="java">void onFinishPrinting(int errorCode);</syntaxhighlight>
{|class="wizarpostable"
|-
! scope="row" colspan="2" | Parameters
|-
| errorCode|| '''int:''' returned value:PRINT_ERROR = 0;PRINT_SUCCESS = 1;BITMAP_ERROR = 2;BITMAP_SUCCESS = 3;DEVICE_NOT_OPEN = 4.
|}
=== Sample with Java SDK API ===
Please refer to java [http://{{SERVERNAME}}/wizarposapi/ API Spec].
Download [http://ftp.wizarpos.com/device/java/CloudPosAPIDemoForAar_1.5.3.071_20210913.zip API demo 1.5.3.071], there is a printHtml method in com.wizarpos.apidemo.action.PrinterAction.java, you can call it like this:
<syntaxhighlight lang="java">
    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));
        }
    }
</syntaxhighlight >
 
== '''JNI API wrapper with C SDK''' ==
=== API Overview ===
==== <big>PrintHtmlInterface.printHTML</big>====
  <syntaxhighlight lang="java">void printHTML(Context context, String htmlcontent, PrinterHtmlListener listener);</syntaxhighlight>
Print HTML content.
 
{|class="wizarpostable"
|-
!  scope="row" colspan="2" | 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.
|}
 
==== <big>PrintHtmlInterface.convert2Image</big>====
  <syntaxhighlight lang="java">void convert2Image(Context context, String htmlContent, PrinterHtmlListener listener);</syntaxhighlight>
Convert the html content to a image, if want print, please call print API of the printer.
 
{|class="wizarpostable"
|-
!  scope="row" colspan="2" | 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.
|}
 
==== <big>PrinterHtmlListener.onGet</big>====
  <syntaxhighlight lang="java">void onGet(Bitmap returbitmap, int result);</syntaxhighlight>
This callback will return the bitmap if you invoke the convert2Image method of the PrintHtmlInterface.
 
{|class="wizarpostable"
|-
!  scope="row" colspan="2" | Returns
|-
| returbitmap|| '''Bitmap :''' The returned bitmap.
|-
| result|| '''int:''' The result of get image, "2:" BITMAP_ERROR, "3:" BITMAP_SUCCESS.
|}
 
==== <big>PrinterHtmlListener.onFinishPrinting</big>====
  <syntaxhighlight lang="java">void onFinishPrinting(int result);</syntaxhighlight>
This callback will be callled after printing if you invoke the printHTML method of the PrintHtmlInterface.
 
{|class="wizarpostable"
|-
!  scope="row" colspan="2" | 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 with JNI API===
Please download the [http://ftp.wizarpos.com/device/c/apidemo_c_20190505.zip API demo 1.5.2]

Latest revision as of 07:39, 7 April 2024

Please visit new link of same subject:

https://smartpossdk.gitbook.io/cloudpossdk/faq/printer/print-unsupported-character-sets

We're making a move! Our site's content is migrating to a new URL, to provide you with an enhanced browsing experience. Please update your bookmarks accordingly. Thank you for your continuous support!