Skip to content

Commit

Permalink
Version v1.0.1
Browse files Browse the repository at this point in the history
- added print character list script,
- added more special characters,
- added removeSpecialCharacters and replaceSpecialCharacters settings
  • Loading branch information
Klemen Kastelic committed Sep 20, 2016
1 parent ffde9c6 commit c018875
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 25 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ $ npm install node-thermal-printer
printer.init({
type: 'star', // Printer type: 'star' or 'epson'
interface: '/dev/usb/lp0', // Printer interface
characterSet: 'SLOVENIA' // Printer character set
characterSet: 'SLOVENIA', // Printer character set
removeSpecialCharacters: false, // Removes special characters - default: false
replaceSpecialCharacters: true // Replaces special characters listed in config files - default: true
});

printer.isPrinterConnected( function(isConnected){ } ) // Check if printer is connected, callback passes bool of status
Expand Down
19 changes: 19 additions & 0 deletions charcode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var printer = require("./node-thermal-printer");
printer.init({
type: 'star', // 'star' or 'epson'
interface: '/dev/usb/lp0',
width: 48, // Number of characters in one line (default 48)
characterSet: 'SLOVENIA' // Character set default SLOVENIA
// ip: "localhost",
// port: 9000
});


for(var i=33; i<255; i++){
printer.print(i + ": ");
printer.add(new Buffer([i]));
printer.print(", ");
}

printer.cut();
printer.execute();
11 changes: 10 additions & 1 deletion configs/epsonConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ module.exports = {
"Đ": 92,
"đ": 124,
"Ć": 93,
"ć": 125
"ć": 125,
"ß": 225,
"ẞ": 225,
"ö": 148,
"Ö": 153,
"Ä": 142,
"ä": 132,
"ü": 129,
"Ü": 154,
"é": 130
}
}
11 changes: 10 additions & 1 deletion configs/starConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ module.exports = {
"Đ": 209,
"đ": 208,
"Ć": 143,
"ć": 134
"ć": 134,
"ß": 225,
"ẞ": 225,
"ö": 148,
"Ö": 153,
"Ä": 142,
"ä": 132,
"ü": 129,
"Ü": 154,
"é": 130
}
}
13 changes: 9 additions & 4 deletions example.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
var printer = require("./node-thermal-printer");
printer.init({
type: 'star', // 'star' or 'epson'
type: 'star', // 'star' or 'epson'
interface: '/dev/usb/lp0',
width: 48, // Number of characters in one line (default 48)
characterSet: 'SLOVENIA' // Character set default SLOVENIA
width: 48, // Number of characters in one line (default 48)
characterSet: 'SLOVENIA', // Character set default SLOVENIA
removeSpecialCharacters: false, // Removes special characters - default: false
replaceSpecialCharacters: true, // Replaces special characters listed in config files - default: true
// ip: "localhost",
// port: 9000
});
Expand All @@ -30,6 +32,9 @@ printer.printImage('./assets/olaii-logo-black-small.png', function(done){
printer.invert(false);
printer.drawLine();

printer.println("Special characters: Č芚ŽžĐđĆćßẞöÖÄäüÜé");
printer.drawLine();

printer.setTypeFontB();
printer.println("Type font B");
printer.setTypeFontA();
Expand Down Expand Up @@ -62,7 +67,7 @@ printer.printImage('./assets/olaii-logo-black-small.png', function(done){
});

printer.pdf417("4126565129008670807191");
printer.printQR("4170807191412657080719141265708");
printer.printQR("https://olaii.com");

printer.newLine();

Expand Down
39 changes: 22 additions & 17 deletions node-thermal-printer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
var unorm = require('unorm');
var combining = /[\u0300-\u036F]/g;
var fs = require('fs'),
PNG = require('node-png').PNG;

Expand All @@ -11,8 +9,8 @@ var writeFile = require('write-file-queue')({

var net = require("net");
var config = undefined;
var printerConfig;
var buffer = null;
var printerConfig;

module.exports = {
init: function(initConfig){
Expand All @@ -24,6 +22,8 @@ module.exports = {

if(!initConfig.width) initConfig.width = 48;
if(!initConfig.characterSet) initConfig.characterSet = "SLOVENIA";
if(typeof(initConfig.removeSpecialCharacters) == "undefined") initConfig.removeSpecialCharacters = false;
if(typeof(initConfig.replaceSpecialCharacters) == "undefined") initConfig.replaceSpecialCharacters = true;

printerConfig = initConfig;
},
Expand Down Expand Up @@ -189,7 +189,7 @@ module.exports = {
drawLine: function(){
// module.exports.newLine();
for(var i=0; i<printerConfig.width; i++){
append(new Buffer("-"));
append(new Buffer([196]));
}
module.exports.newLine();
},
Expand Down Expand Up @@ -790,18 +790,28 @@ var setInternationalCharacterSet = function(charSet){


var append = function(buff){

if(typeof buff == "string"){
buff = unorm.nfkd(buff).replace(combining, '');

// Remove special characters
if(printerConfig.removeSpecialCharacters) {
var unorm = require('unorm');
var combining = /[\u0300-\u036F]/g;
buff = unorm.nfkd(buff).replace(combining, '');
}

var endBuff = null;
for(var i=0; i<buff.length; i++){
var value = buff[i];
var tempBuff = new Buffer(value);

// Replace special characters
for(var key in config.specialCharacters){
if(value == key){
tempBuff = new Buffer([config.specialCharacters[key]]);
break;
if(printerConfig.replaceSpecialCharacters) {
for(var key in config.specialCharacters){
if(value == key){
tempBuff = new Buffer([config.specialCharacters[key]]);
break;
}
}
}

Expand All @@ -812,18 +822,13 @@ var append = function(buff){
buff = endBuff;
}




// Append character set
if(!buffer && printerConfig.characterSet) buffer = setInternationalCharacterSet(printerConfig.characterSet);

// Append new buffer
if (buffer) {
buffer = Buffer.concat([buffer,buff]);
} else {
buffer = buff;
}
};


var fix = function(str){
return unorm.nfkd(str).replace(combining, '');
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-thermal-printer",
"version": "1.0.0",
"version": "1.0.1",
"description": "Made to work with Epson and Star thermal printers",
"main": "node-thermal-printer.js",
"scripts": {
Expand Down

0 comments on commit c018875

Please sign in to comment.