CesarBalzer / Cordova-Plugin-BTPrinter

A cordova plugin for bluetooth printer for android platform
Apache License 2.0
80 stars 63 forks source link

Encoding problems #37

Open manbuv opened 3 years ago

manbuv commented 3 years ago

Hello everyone, I am unfortunately desperate. I can't get the right encoding. Special characters, currency symbols and umlauts are displayed as strange characters. Does anyone have an idea?

Thanks a lot

andreszs commented 3 years ago

Why don't you expand on that by adding the characters you send and a photo of the printed receipt? Otherwise there's not much to proceed. Printer brand and model would also help.

manbuv commented 3 years ago

@andreszs ok sorry, here is a picture. I tested it on the printer in the image (mini thermal printer pos-5802dd) and also on the Sunmi inner printer v1.

Bildschirmfoto 2020-12-03 um 23 48 18
andreszs commented 3 years ago

Have you tried using the setEncoding button with ISO-8859-1 first? Also try these encodings, they are all the same:

One of these should set the proper encoding for printing correctly my name and other latin chars.

manbuv commented 3 years ago

@andreszs tried all encoding, even before that I tried the common ones. unfortunately no resul.

Bildschirmfoto 2020-12-04 um 18 28 27

andreszs commented 3 years ago

All I can suggest at this point is to send a battery of POS commands until you get the right one. Check out these articles:

Remember to send decimal values in hexadecimal, for example, to set the Denmark II character set (10) send it as 0A. The full POS command to set this charset would be 1B520A.

ilkersurmeli commented 2 years ago

I also try to print Ää ö characters as is in Finnish lagauge

qqqqq

I tried all possibilities like: BTPrinter.setEncoding(function(data){ console.log("Success"); console.log(data) },function(err){ console.log("Error"); console.log(err) }, "CP437") and CP850, Windows-1252. Nothing helped. There is some more information nest image there but I don't know what to do with that.

qqqqq

Any help?

andreszs commented 2 years ago

In this case use CP437 in the setEncoding method, but also send the POS commands beforehand to set te printer's encoding as follows.

According the the manual, they use the ancient CP437 for American and European text. You could apply this charset by sending 1C2Efollowed by a 1B7400. If this does not print characters correctly, maybe you could find a javascript method to convert UTF-8 strings to CP437 and send your properly encoded text.

Also try setting the printer to UTF-8 by sending the POS commands 1C26 (multi-byte encoding ON) and then 1C43FF (UTF-8 encoding mode), then send the text with UTF8 encoding.

You could also test random encodings by creating a loop as follows:

  1. Send 1C2Eto set single byte mode
  2. Send one of all possible HEX values between 1B7400and 1B74FF
  3. Print a line of text (and the encoding as a reference)
ilkersurmeli commented 2 years ago

Thanks mate:) I will try it!

On Mon, 13 Dec 2021 at 16:05, Andrés @.***> wrote:

In this case do not use the setEncoding method, instead send the POS commands manually.

According the the manual, they use the ancient CP437 https://en.wikipedia.org/wiki/Code_page_437 for American and European text. You could apply this charset by sending 1C2E followed by a 1B7400. If this does not print characters correctly, maybe you could find a javascript method to convert UTF-8 strings to CP437 and send your properly encoded text.

Also try setting the printer to UTF-8 by sending the POS commands 1C26 (multi-byte encoding ON) and then 1C43FF (UTF-8 encoding mode), then send the text with UTF8 encoding.

You could also test random encodings by creating a loop as follows:

  1. Send 1C2E to set single byte mode
  2. Send one of all possible HEX values between 1B7400 and 1B74FF
  3. Print a line of text (and the encoding as a reference)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/CesarBalzer/Cordova-Plugin-BTPrinter/issues/37#issuecomment-992513077, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACD5WHGHN27FV6A37SJG44LUQX4RBANCNFSM4ULACLYQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

ilkersurmeli commented 2 years ago

Hi again, I am not good at coding so I could not succeed doing what you said. I couldn't find information as well. Can you also tell me how I can send 1C2E followed by a 1B7400? Below is the example part of code, maybe you can check. Can you write how to send in the code?:)

function bluetoothprint() {

$('#cover-spin').show(); if (true) { corder = currentorder; let info = corder.data.order_data;

let company = ""; if (corder.data.order_data && corder.data.order_data.merchant_name) company = corder.data.order_data.merchant_name;

let cashier = "Self"

let res_address = ""; if (corder.data.order_data.merchant_address) res_address = corder.data.order_data.merchant_address;

let resNumber = "" if (corder.data.order_data.merchant_contact_phone) resNumber = corder.data.order_data.merchant_contact_phone // let amoutntReceived = 400 // let change = amoutntReceived - totalPrice

let receipt = "" receipt += '\x1b\x61\x01 \x1b\x21\x30' + company receipt += commands.TEXT_FORMAT.TXT_NORMAL receipt += '\n' receipt += commands.HORIZONTAL_LINE.HR_58MM receipt += '\n' receipt += '\x1b\x61\x01' + company receipt += commands.TEXT_FORMAT.TXT_NORMAL receipt += '\n' receipt += '\x1b\x61\x01' + res_address receipt += '\n' receipt += '\x1b\x61\x01' + resNumber receipt += '\n' receipt += commands.HORIZONTAL_LINE.HR_58MM receipt += '\n' receipt += "\x1b\x61\x01 \x1b\x21\x30"; //receipt += '\x1B' + '\x61' + '\x30'// left align receipt += capitalize(t(info.trans_type)) + ":" + info.order_id receipt += commands.TEXT_FORMAT.TXT_NORMAL receipt += '\n' receipt += '\n' //receipt += vsprintf("%-17s %3s %10s\n", [capitalize(corder.trans_type), "" ,corder.order_id ])

wloges commented 1 year ago

BTPrinter.setEncoding(function(data){ console.log("Success"); console.log(data) },function(err){ console.log("Error"); console.log(err) }, "ISO-8859-1")

No log on Success on either Error. Lost one day for looking bug in my app :(