Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to print arabic #26

Open
vinothmoorthkumar opened this issue Jul 4, 2018 · 33 comments
Open

Unable to print arabic #26

vinothmoorthkumar opened this issue Jul 4, 2018 · 33 comments

Comments

@vinothmoorthkumar
Copy link

vinothmoorthkumar commented Jul 4, 2018

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

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

@NielsLeenheer
Copy link
Owner

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.

@vinothmoorthkumar
Copy link
Author

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

@NielsLeenheer
Copy link
Owner

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.

@vinothmoorthkumar
Copy link
Author

Can you please give me any example.. please

@tresf
Copy link
Contributor

tresf commented Jul 31, 2018

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: qzind/tray#339 (comment)

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-

@NielsLeenheer
Copy link
Owner

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

@williamrizqallah
Copy link

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?

@tresf
Copy link
Contributor

tresf commented Jul 22, 2019

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.

@williamrizqallah
Copy link

@tresf Could you send me an example, please

@williamrizqallah
Copy link

williamrizqallah commented Jul 22, 2019

@tresf This is my case

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

@tresf
Copy link
Contributor

tresf commented Jul 22, 2019

@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.

@vinothmoorthkumar
Copy link
Author

@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

@williamrizqallah
Copy link

@vinothmoorthkumar Thanks for your response

Could you please show me an example

@sanik
Copy link

sanik commented Nov 15, 2019

Did you manage to solve this problem?

@vinothmoorthkumar
Copy link
Author

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()
});
});
`

@musahaidari
Copy link

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);
});

@alimuhnad
Copy link

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

@jadallah
Copy link

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

@Waheed-Rumaneh
Copy link

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

@jadallah

use encoding: 'Arabic', codepage: 22,

@amalnafia
Copy link

@Waheed-Rumaneh
it did not work

@Waheed-Rumaneh
Copy link

@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

@amalnafia
Copy link

@Waheed-Rumaneh

i am working with android device

@jadallah
Copy link

@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

@bazl-E
Copy link

bazl-E commented Dec 7, 2021

EscPosEncode

does this works,which converter are you using

@blackangiliq
Copy link

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

@laithbzour
Copy link

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

@yaser-elbatal
Copy link

how can you print arabic ?

@yaser-elbatal
Copy link

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 ?

@laithbzour
Copy link

@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

@yaser-elbatal
Copy link

@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

@alimuhnad
Copy link

alimuhnad commented Sep 7, 2022

I fix this problem by ......
1-make the text as image
2-print the image as base64
I used this method in 2018 but i forget to close the issue .... There is no another way for Arabic language

@laithbzour
Copy link

@yaser-elbatal sure :
try {
EscPosPrinter printer = new EscPosPrinter(MyBluetoothPrintersConnections.selectFirstPairedOne(), 203, 58f, 20);
StringBuilder textToPrint = new StringBuilder();
splitImage(yourBitmap, splitImg->{
textToPrint.append("[C]" + PrinterTextParserImg.bitmapToHexadecimalString(printer, splitImg) + "\n"+
"[L]\n");
});
textToPrint.append("[C]--------------------------------\n");
printer.printFormattedTextAndCut(textToPrint.toString());
} catch (EscPosConnectionException e) {
e.printStackTrace();
} catch (EscPosEncodingException e) {
e.printStackTrace();
} catch (EscPosBarcodeException e) {
e.printStackTrace();
} catch (EscPosParserException e) {
e.printStackTrace();
}

@laithbzour
Copy link

laithbzour commented Sep 8, 2022

@yaser-elbatal

use this lib to build bitmap from text :
compile 'com.github.danielfelgar:draw-receipt:0.1.3'

private  Bitmap greatBitmapText(String text){
    ImageBuilder  receipt = new ImageBuilder(400);
            receipt.setMargin(5, 1).
            setAlign(Paint.Align.LEFT). ---> change it to "CENTER" or "RIGHT" 
            setColor(Color.parseColor("#85929E")).
            setTextSize(28).
            addText(text)
    return receipt.build();
}

@NielsLeenheer NielsLeenheer transferred this issue from NielsLeenheer/EscPosEncoder Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests