giorgiofellipe / cordova-plugin-datecs-printer

Cordova plugin to print on Mobile Bluetooth ESC/POS Printers - Tested on Datecs DPP-250 Printer
MIT License
73 stars 60 forks source link

unable to print the Qrcode in epson TMp20 model #118

Open kavinRkz opened 5 years ago

kavinRkz commented 5 years ago

unable to print the Qrcode any one give an better sollution for this

window.DatecsPrinter.listBluetoothDevices( function (devices) { window.DatecsPrinter.connect(devices[0].address, function() { printMyQRCode(); }, function() { alert(JSON.stringify(error)); } ); }, function (error) { alert(JSON.stringify(error)); } );

function printMyQRCode() { window.DatecsPrinter.printQRCode( 4, // qr code size 4, // qr code error correction 'http://www.datecs.bg', // barcode data function() { alert('success!'); }, function() { alert(JSON.stringify(error)); } ); }

csleeds commented 5 years ago

if your case happens to be print out the text alone, it might due to your printer is not supported to print by this way, try this instead which i amended based on the sample from read me file:

//Create QR Code with node-qrcode package
//https://github.com/soldair/node-qrcode

var QRCode = require('qrcode');

//Generate the QR image
QRCode.toDataURL('http://www.datecs.bg/', { errorCorrectionLevel: 'H', width: 250 }, function (err, url) {

    var canvas = document.createElement('canvas');
    canvas.height = 250;
    canvas.width = 250;
    var context = canvas.getContext('2d');
    var image = new Image();
    image.src = url;

    image.onload = function () {
        context.drawImage(image, 0, 0);
        var imageData = canvas.toDataURL('image/jpeg').replace(/^data:image\/(png|jpg|jpeg);base64,/, ""); //remove mimetype
        window.DatecsPrinter.printImage(
            imageData, //base64
            canvas.height,
            canvas.width,
            //align
            1,
            function () {
                //alert("Print Qrcode cmd sent!");
            },
            function (error) {
                alert(JSON.stringify(error));
            }
        );
    };
});

Let me know if it works for you too, cheers!