mike42 / escpos-php

PHP library for printing to ESC/POS-compatible thermal and impact printers
Other
2.57k stars 861 forks source link

Support Armenian language #780

Open levon1991 opened 5 years ago

levon1991 commented 5 years ago

Hi Mike When will you add support Armenian language?

I read about that in your forum https://github.com/receipt-print-hq/escpos-printer-db/issues/31 but it is 2 year ago.

mike42 commented 5 years ago

Hi @levon1991 - any solution involving printer profiles will be highly printer-specific, can you share some information about which hardware and OS you are using?

I can basically confirm that this example will only get you a string of "??????" on the default profile, which is what you would use for Epson printers.

<?php
/* Call this file 'hello-world.php' */
require __DIR__ . '/vendor/autoload.php';
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
use Mike42\Escpos\Printer;
$connector = new FilePrintConnector("php://stdout");
$printer = new Printer($connector);
$printer -> text("Կրնամ ապակի ուտել և ինծի անհանգիստ չըներ\n");
$printer -> cut();
$printer -> close();

However, if you need this to work and are prepared to work with something that is prototype-quality, then I would suggest reading this blog post. I have never finished working on custom font support, but you can absolutely print Armenian on a good ESC/POS printer.

You can clone the code here, and get unifont here. You need to locate unifont-12.1.03.tar.gz, and extract font/precompiled/unifont-12.1.03.hex.

You then set a path and some text -

diff --git a/unifont-bitmap-font/unifont-example.php b/unifont-bitmap-font/unifont-example.php
index 374431c..e1ef080 100644
--- a/unifont-bitmap-font/unifont-example.php
+++ b/unifont-bitmap-font/unifont-example.php
@@ -515,7 +515,7 @@ class UnifontCodeSource implements ColumnFormatGlyphFactory {
     }

     public function __construct() {
-        $unifont = "/usr/share/unifont/unifont.hex";
+        $unifont = "unifont-12.1.03.hex";
         $this -> unifontFile = explode("\n", file_get_contents($unifont));
     }

@@ -722,11 +722,11 @@ class UnicodePrintBuffer implements PrintBuffer {
     }
 }

-$text = file_get_contents("php://stdin");
+$text = "Հայերեն     ֏55,000\n";
 $connector = new FilePrintConnector("php://stdout");
 $printer = new Printer($connector);
 $printer -> text($text);
 $printer -> cut();
 $printer -> close();

-?>
\ No newline at end of file
+?>

And you can go printing receipts with basically any character set on them, just without image, correct spacing, or other luxuries :)

$ php unifont-example.php > /dev/usb/lp0

receipt-example

This is all on an Epson TM-T20II on Debian, but maybe it will also be useful in your setup.

levon1991 commented 5 years ago

I try to run this script and want to print in terminal but it printed this


levon@debian:/var/www/html/models/print_test/escpos-snippets/unifont-bitmap-font$ php unifont-example.php P� ����x((��*** VAlevon@debian:/var/www/html/models/print_test/escpos-snippets/unifont-bitmap-font$


if it can't print in termianl I assume it wouldn't print in pos printer to.

I change this

mike42 commented 5 years ago

@levon1991 - The command I ran redirected that binary to /dev/usb/lp0, which is where my TM-T20II printer appears (it is connected via USB).

Can you share some information about the type of printer you have, and how it is connected? I should be able to point you in the right direction if it's something common.

levon1991 commented 5 years ago

type of my printer SP-POS888U, now I can print check in armenian language but I have problem with hade of text 2019-10-06 12-46-48 what I can do to fix this problem

levon1991 commented 5 years ago

Cuting head of text it's depend on type of printer or it's libery problem?

yayidg22 commented 5 months ago

@levon1991 Hello, did you solve the cut head problem?