EscPosEncoder icon indicating copy to clipboard operation
EscPosEncoder copied to clipboard

Unable to print arabic

Open vinothmoorthkumar opened this issue 6 years ago • 33 comments

Its printing ????. I can able to print chines...But arabic is not printing Please help

encoder .codepage('cp864') .text('جريدة') .newline() .cut('partial') .encode()

vinothmoorthkumar avatar Jul 04 '18 07:07 vinothmoorthkumar

I've done a quick test and it appear that the data I get back from iconv-lite, which does the code page translation, already contain the question marks. So it is not an issue with the printer or EscPosEncoder itself.

I'm not exactly sure why that is happening, except that the unicode code points in the string "جريدة" are not in the translation table. Perhaps the strings needs to be normalised or something. I'll follow up once I have more information.

NielsLeenheer avatar Jul 04 '18 08:07 NielsLeenheer

Thank you. Its is working fine. Actually codepage i wrong what i gave.. Now its printing but it is printing arabic from left to right. I want to print from right to left. Please help

vinothmoorthkumar avatar Jul 04 '18 13:07 vinothmoorthkumar

The problem with ESC/POS printers is that they are pretty dumb. You can basically print the arabic characters that the codepage provides and that is it. Things like right-to-left support and glyph shaping is simply not supported.

My advice for proper arabic printing is to create a bitmap, draw a text string and print that.

NielsLeenheer avatar Jul 10 '18 12:07 NielsLeenheer

Can you please give me any example.. please

vinothmoorthkumar avatar Jul 10 '18 12:07 vinothmoorthkumar

The problem with ESC/POS printers is that they are pretty dumb. You can basically print the arabic characters that the codepage provides and that is it. Things like right-to-left support and glyph shaping is simply not supported.

Just got an Epson TM-T88VI which is the latest T88 model at the time of writing this and there are some Arabic settings using a special Epson utility. Here's some more information: https://github.com/qzind/tray/pull/339#issuecomment-404016953

We're using a 3rd party library -- ICU -- that can get the UTF-8 glyph shaping and simplify it to IBM864. It's written in Java and C++: http://site.icu-project.org/#TOC-What-is-ICU-

tresf avatar Jul 31 '18 03:07 tresf

Yes, I am aware of ICU and that would indeed work. However I am not aware of a Javascript implementation of ICU, apart from an enscriptem compiled C version. But that has a pretty high footprint to include with the library.

Mapbox actually uses Enscriptem compiled subset of ICU for pretty much the same purpose, rendering Arabic script on a WebGL map: https://github.com/mapbox/mapbox-gl-rtl-text

NielsLeenheer avatar Aug 08 '18 10:08 NielsLeenheer

Thank you. Its is working fine. Actually codepage i wrong what i gave.. Now its printing but it is printing arabic from left to right. I want to print from right to left. Please help

Hi @vinothmoorthkumar How did you manage to print Arabic text?

williamrizqallah avatar Jul 22 '19 14:07 williamrizqallah

How did you manage to print Arabic text?

Chiming in, if you have the IBM-864 characters (NOT the UTF-8) characters and a printer that supports IBM-864, this should work. As noted above, the bytes may need to be swapped.

Since 99% of websites are UTF-8, this makes Arabic very difficult natively (hence the conversation about about the ICU translation). Feel free to email me directly for more info about how I solved this problem. I believe most programmers give up with Arabic and send a raster image or PDF instead.

tresf avatar Jul 22 '19 14:07 tresf

@tresf Could you send me an example, please

williamrizqallah avatar Jul 22 '19 14:07 williamrizqallah

@tresf This is my case

encodeWords(word){ this.encoder = new EscPosEncoder(); let result = this.encoder .codepage('cp864') .text(word) .encode(); return result; }

williamrizqallah avatar Jul 22 '19 14:07 williamrizqallah

@williamrizqallah out of respect of this project, I'm not going to cross-reference my solution, it's in Java and for a commercial product. My email address is in my GitHub profile if interested.

tresf avatar Jul 22 '19 14:07 tresf

@williamrizqallah I m using https://www.npmjs.com/package/canvas Canvas. I m creating canvas image and printing using https://www.npmjs.com/package/escpos

vinothmoorthkumar avatar Jul 22 '19 16:07 vinothmoorthkumar

@vinothmoorthkumar Thanks for your response

Could you please show me an example

williamrizqallah avatar Jul 22 '19 16:07 williamrizqallah

Did you manage to solve this problem?

sanik avatar Nov 15 '19 12:11 sanik

Here is my code

`const { createCanvas, loadImage, Image } = require('canvas'); var escpos = require('escpos');

canvas= createCanvas(580, 700) var ctx = canvas.getContext("2d"); ctx.textAlign = "center"; ctx.font = "30px bold"; ctx.fillText('مرحبا بالعالم',50, 50);

device.open(function () { escpos.Image.load(canvas.toDataURL(), function (rasterimage) { printer.raster(rasterimage) printer.cut() printer.close() }); }); `

vinothmoorthkumar avatar Nov 15 '19 18:11 vinothmoorthkumar

Just modified @vinothmoorthkumar code little bit to work with printer and node-thermal-printer:

const importedThermalPrinter = require('node-thermal-printer').printer;
const thermalPrinterTypes = require('node-thermal-printer').types;
const printer = require('printer');

const fetchedPrinter = printer.getPrinter('POS-80');

const createCanvas = require('canvas');

canvas = createCanvas(580, 700)
var ctx = canvas.getContext("2d");
ctx.textAlign = "left";
ctx.font = "30px bold";
ctx.fillText(' مرحبا بالعالم', 50, 50);

const thermalPrinter = new importedThermalPrinter({
    type: thermalPrinterTypes.EPSON,
})
thermalPrinter.printImageBuffer(canvas.toBuffer()).then((s) => {

    printer.printDirect({
        data: thermalPrinter.getBuffer(),
        printer: fetchedPrinter.name,
        type: "RAW",
        success: function (job_id) {
            console.log('OK :' + job_id);
        },
        error: function (err) {
            console.error(err);
        }
    });
}, (e) => {
    console.error(e);
});


musahaidari avatar Jul 29 '20 07:07 musahaidari

u can use .codepage('iso88596') or .codepage('windows1256') it will work

alimuhnad avatar Aug 23 '20 06:08 alimuhnad

hello my printer is print ?????? when use .codepage('iso88596') or .codepage('windows1256') any fix please

jadallah avatar Apr 28 '21 21:04 jadallah

hello my printer is print ?????? when use .codepage('iso88596') or .codepage('windows1256') any fix please

@jadallah

use encoding: 'Arabic', codepage: 22,

Waheed-Rumaneh avatar Jul 15 '21 13:07 Waheed-Rumaneh

@Waheed-Rumaneh it did not work

amalnafia avatar Sep 13 '21 09:09 amalnafia

@amalnafia

yes i researched about it and it's worked for some printer Each printer have difference code so you can't build a general code

the best way i used and it's worked prefect :

  • build your style that you want to print as react native style
  • contain your style inside ViewShot component
  • take a temporary screenshoot for this section
  • print the screenshoot then delete it
  • this solution worked with all printer
  • this link will help you : https://github.com/januslo/react-native-bluetooth-escpos-printer/issues/77#issuecomment-696225197

Waheed-Rumaneh avatar Sep 13 '21 10:09 Waheed-Rumaneh

@Waheed-Rumaneh

i am working with android device

amalnafia avatar Sep 13 '21 10:09 amalnafia

@amalnafia i was able to print arabic by make the invoice as photo with server side then use this plugin to print photo and it work perfect

jadallah avatar Sep 13 '21 13:09 jadallah

EscPosEncode

does this works,which converter are you using

bazl-E avatar Dec 07 '21 16:12 bazl-E

u can use this

you can check this

this repo use 3 laiblary

secreenshot to convert widget to image and image library to convert it to uint8 and pos_print to print it ass u love to show

https://github.com/blackangiliq/flutter_pos_printer_spport_arabic

blackangiliq avatar Mar 23 '22 00:03 blackangiliq

you need to convert text to bitmap image .. if image too height then after convert to bitmap split image to chunk note : you must get max width of printer to rescale image

laithbzour avatar Aug 08 '22 10:08 laithbzour

how can you print arabic ?

yaser-elbatal avatar Sep 06 '22 11:09 yaser-elbatal

Thank you. Its is working fine. Actually codepage i wrong what i gave.. Now its printing but it is printing arabic from left to right. I want to print from right to left. Please help

How you solve it to be able print Arabic ?

yaser-elbatal avatar Sep 06 '22 11:09 yaser-elbatal

@yaser-elbatal use this command before print : byte[] ESC_ALIGN_LEFT = new byte[] { 0x1b, 'a', 0x00 }; byte[] ESC_ALIGN_RIGHT = new byte[] { 0x1b, 'a', 0x02 }; byte[] ESC_ALIGN_CENTER = new byte[] { 0x1b, 'a', 0x01 };

thanks

laithbzour avatar Sep 07 '22 16:09 laithbzour

@yaser-elbatal use this command before print : byte[] ESC_ALIGN_LEFT = new byte[] { 0x1b, 'a', 0x00 }; byte[] ESC_ALIGN_RIGHT = new byte[] { 0x1b, 'a', 0x02 }; byte[] ESC_ALIGN_CENTER = new byte[] { 0x1b, 'a', 0x01 };

thanks

with EscPosEncoder or Canvas ? can you share code please ? @laithbzour

yaser-elbatal avatar Sep 07 '22 18:09 yaser-elbatal