Open nik-hal opened 4 years ago
try it's
BTPrinter.list(function (data) {
console.log("Success");
console.log(data); //list of printer in data array
BTPrinter.connect(function (data) {
console.log("Success");
console.log(data)
//init commands pos inner connect
BTPrinter.printPOSCommand(function (data) {
console.log("Success");
console.log(data)
}, function (err) {
console.log("Error");
console.log(err)
}, "1B 69 61 0");
//.......others
}, function (err) {
console.log("Error");
console.log(err)
}, "QL-820NWB4976");
}, function (err) {
console.log("Error");
console.log(err);
});
It didn't work. Here is how debug looks like, I did something wrong in code? https://youtu.be/J8VZ4kYAlLY
As I said earlier, the functions for printing POS commands, must be within the connect function, which is within the list function, I am also not sure of the POS commands you are using, it depends on each type of printer, maybe the command does not be recognized by the plugin. This code snippet is exactly how I use it, but from what I noticed your POS commands don't follow the same pattern as mine, in read.me you have this example of "paper feed" with the command "0C" (zero, C) , only try it 3 times repeatedly to activate the printer. This should at least rotate the paper, I will leave the code snippet for you to test.
A hint:
To test this command as long as the printer is already connected, you can paste it directly into the debug console on the same screen as the video shown and enter, without specifying to build the cordova app again.
BTPrinter.list(function (data) {
console.log("Success");
console.log(data); //list of printer in data array
BTPrinter.connect(function (data) {
console.log("Success");
console.log(data)
BTPrinter.printPOSCommand(function (data) {
console.log("Success");
console.log(data)
}, function (err) {
console.log("Error");
console.log(err)
}, "0C");
BTPrinter.printPOSCommand(function (data) {
console.log("Success");
console.log(data)
}, function (err) {
console.log("Error");
console.log(err)
}, "0C");
BTPrinter.printPOSCommand(function (data) {
console.log("Success");
console.log(data)
}, function (err) {
console.log("Error");
console.log(err)
}, "0C");
}, function (err) {
console.log("Error");
console.log(err)
}, "QL-820NWB4976");
}, function (err) {
console.log("Error");
console.log(err);
});
I tried all, but the ones that is working is only text string to print. Any suggestion? Can we print the whole page of html?
@stratonlive, you will not be able to print the html, html tags are not supported within the plugin
POS command 0C
does nothing in my generic portable printer, but 0A
does advance the feed properly. Maybe this should be documented. You can try it with my BTPrinter plugin demo app.
@stratonlive Currently, I used for html element as below. It's worked.
let element = $("#print-section");
let canvasConfig = {
allowTaint: true,
imageTimeout: 15000,
logging: true,
useCORS: true,
scrollY: -window.scrollY,
width: window.ricev_w,
height: window.ricev_h
};
window.scrollTo(0,0);
window.ricev_h = element.height()+50; //canvas height
window.ricev_w= 365; // canvas width
html2canvas(element, canvasConfig).then(canvas => {
var imageData = canvas.toDataURL().replace(/^data:image\/\w+;base64,/, "");
console.log("Successfully export image");
BTPrinter.printBase64(function(){
console.log("Success Printing");
imageData = null;
BTPrinter.printPOSCommand(null, null, "0A");
BTPrinter.printPOSCommand(null, null, "0A");
BTPrinter.printPOSCommand(null, null, "0A");
BTPrinter.printPOSCommand(null, null, "0A");
setTimeout(function(){
BTPrinter.disconnect(function(){
console.log("Success Disconnect");
console.log(data)
},function(err){
console.log("Error Disconnect");
console.log(err)
}, "Printer Name");
}, time);
},function(err){
console.log("Error Printing");
},imageData, 0);
});
I maybe have issue in commands, but printer buffer have all data. But not printing. I using printer Brother QL-820NWB.
Here is code: https://pastebin.com/raw/vA9e1LfD