Skip to content

Instantly share code, notes, and snippets.

@lite1979
Created December 5, 2018 17:41
Show Gist options
  • Save lite1979/30cb2c6d5ea50fd8a59a6effe837e882 to your computer and use it in GitHub Desktop.
Save lite1979/30cb2c6d5ea50fd8a59a6effe837e882 to your computer and use it in GitHub Desktop.
function printESCP() {
var config = qz.configs.create("Epson-TM-BA-Thermal");
var data = [{
type: 'html',
format: 'plain', // or 'plain' if the data is raw HTML
data: ' <html><header><title>This is the title</title></header><body>Hello world</body></html>'
}];
qz.print(config, data)
.then(function() {
var config = qz.configs.create("Epson-TM-BA-Thermal");
var data = [{
type: 'image',
data: 'assets/img/image_sample.png'
}];
return qz.print(config, data);
})
.then(function() {
var config = qz.configs.create("Epson-TM-BA-Thermal",{altPrinting:true});
var printData = [
'\x1B' + '\x40', // init
'\x1B' + '\x61' + '\x31', // center align
'Canastota, NY 13032' + '\x0A',
'\x0A', // line break
'www.qzindustries.com' + '\x0A', // text and line break
'\x0A', // line break
'\x0A', // line break
'November 21, 2015 3:09 PM' + '\x0A',
'\x0A', // line break
'\x0A', // line break
'\x0A',
'Transaction # 123456 Register: 3' + '\x0A',
'\x0A',
'\x0A',
'\x0A',
'\x1B' + '\x61' + '\x30', // left align
'Baklava (Qty 4) 9.00' + '\x1B' + '\x74' + '\x13' + '\xAA', //print special character symbol after numeric value
'\x0A',
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' + '\x0A',
'\x1B' + '\x45' + '\x0D', // bold on
'Here\'s some bold text!',
'\x1B' + '\x45' + '\x0A', // bold off
'\x0A' + '\x0A',
'\x1B' + '\x61' + '\x32', // right align
'\x1B' + '\x21' + '\x30', // em mode on
'DRINK ME',
'\x1B' + '\x21' + '\x0A' + '\x1B' + '\x45' + '\x0A', // em mode off
'\x0A' + '\x0A',
'\x1B' + '\x61' + '\x30', // left align
'------------------------------------------' + '\x0A',
'\x1B' + '\x4D' + '\x31', // small text
'EAT ME' + '\x0A',
'\x1B' + '\x4D' + '\x30', // normal text
'------------------------------------------' + '\x0A',
'normal text',
'\x1B' + '\x61' + '\x30', // left align
'\x0A' + '\x0A' + '\x0A' + '\x0A' + '\x0A' + '\x0A' + '\x0A',
'\x1B' + '\x69', // cut paper
];
return qz.print(config, printData);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment