Skopje, Macedonia
+389 78 203 673
Opening hours: 8am to 6pm
Skopje, Macedonia

ESC POS with Raw Printing in PrintNode

ESC POS with Raw Printing in PrintNode

I was working on a Thermal printer module for our Restaurant Platforms, and found that the easiest and most stable way to achieve that will be thought PrintNode using their REST API.

All was going ok. I downloaded their client, the thermal printer was shown ( given an ID ).

The I used Postman to work with the API of PrintNode. Started by testing the authentication, listing of printers and then the most important part, to create a print job.

The best way to print on ESC POS enabled printer ( like the one I had, and most receipt printers ) is to use raw_base64 printing. This means to send all the print commands in base64 format.

But this is where I run into a problem. How to write ESC/POS commands. With a good reading of this article, I think finally figure it out. So for you not to waste the time, here is a sample code I did in PHP to get me raw_base64 string that I need to send to PrintNode.

$ESC = "\e";
$GS = chr(29);
$InitializePrinter = "@";
$nl="\n"; //Single new line
$dnl=$nl.$nl; //Double new line
$BoldOn = $ESC . "E" . "1";
$BoldOff = $ESC . "E" . "0";
$DoubleOn = $GS . "!" . "16";  // 2x sized text (double-high + double-wide)
$DoubleOff = $GS . "!" . "0";
$jLeft=$ESC."a"."0";//allign Left
$jCenter=$ESC."a"."1";//allign Center
$jRight=$ESC."a"."2";//allign Right

$cmd=$ESC.$InitializePrinter."FoodTiger Recepie #112".$nl;
$cmd.=$BoldOn."My Bold text".$BoldOff." no more bold".$nl;
$cmd.="Regular allign".$nl;
$cmd.=$jLeft."Left allign".$nl;
$cmd.=$jCenter."Center allign".$nl;
$cmd.=$jRight."Right allign".$nl;
$cmd.=$jLeft."VAT:".$jRight."45 $".$nl;

echo base64_encode($cmd);

At the end of this code, you do get the raw_base64 string that you can send to PrintNode.

Related Posts
Leave a Reply

Your email address will not be published.Required fields are marked *