srehanuddin / cordova-plugin-bluetooth-printer Goto Github PK
View Code? Open in Web Editor NEWA cordova plugin for bluetooth printer for android platform
A cordova plugin for bluetooth printer for android platform
I have error like " ionic.bundle.js:26794 Error: [$injector:unpr] Unknown provider: $BTPrinterProvider <- $BTPrinter <- printBt "
anyone can help me how to use it
My Code
.controller('printBt',['$scope', '$BTPrinter' ,function($scope, $BTPrinter) {
$scope.printbtes = function(){
var doc ="tes";
$BTPrinter.connect().then(function(res) {
console.log("success");
console.log(data);
},function(err){
console.log("Error");
console.log(err);
}, "PrinterName")
}
}])
Could somebody please let me know, why it's not working with my Ionic project? I just created a test project to test the plugin.
https://github.com/OliverTr54/bletest.git
I did some alerts to figure out, if the function is started or not, but after the first alert - executing the BTPrinter.... I get no other alert anymore, neither on success or error :( What am I doing wrong?
I use Ionic 3:
global packages:
@ionic/cli-utils : 1.4.0
Cordova CLI : 7.0.1
Ionic CLI : 3.4.0
local packages:
@ionic/app-scripts : 1.3.8
@ionic/cli-plugin-cordova : 1.4.0
@ionic/cli-plugin-ionic-angular : 1.3.1
Cordova Platforms : none
Ionic Framework : ionic-angular 3.4.2
System:
Node : v6.10.3
OS : Windows 10
Xcode : not installed
ios-deploy : not installed
ios-sim : not installed
npm : 3.10.10
I currently test my development by using Ionic View.
When the BTPrinter is offline or BtPrinter is far away from phone device, below function's error callback is late. How can I decrease that time limit?
BTPrinter.connect(function(data){
alert("success");
},function(err){
alert("error");
}, "PrinterName");
Is it possible to print the HTML designed documents using this plugin.
Sir,
I need phonegap build address of cordova-plugin-bluetooth-printer.
Please provide
Thanking you
Hi, I am not able to connect my bluetooth printer ., getting connected first time and after few seconds immediately got connection aborted error.Please help me
Hi,
Thank you for this wonderful plugin. is there any way that we can print string like table [formatted string].
for ex if table column data exceeds its width size then it will aromatically wraps string within that cell.
i tried by converting html dom element as canvas and send base64 string to printer but it prints ascii and non readable chars.
kindly let me if there are any ways to print pdf.
regards,
I got success message but data is not print the data in printer can someone please help me what i did mistake
$scope.getconnect = function(printername){
alert(printername);
alert('Printer Start');
$scope.doc = "\n TESTING \n PULSA.1 \n KIOS SAYA \n Term : 10006062 \n Ref. No. Bank : 00000000050 \n PEMBELIAN VOUCHER \n manoj \n No Hp : manoj \n No. Seri : 0010101 \n Nominal : manoj \n \n \n ";
$scope.test = JSON.stringify($scope.doc);
alert($scope.test);
BTPrinter.connect(function(data){
alert(" Connected...");
alert(data);
BTPrinter.printText(function(data){
alert("Success print");
alert(data)
BTPrinter.disconnect(function(data){
alert("Success disconnected");
alert(data)
},function(err){
alert("Error disconnecting!");
alert(err)
}, printername);
},function(err){
alert("Error Print!");
alert(err);
}, $scope.test);
},function(err){
alert("Error Connecting!!");
//alert(err);
alert(err);
}, printername);
}
I'm printing in spanish and this character ¡
, is not used in english, so how would i make it happen? it shows a weird subindexed T
and a weird í
instead.
I was taking a look at http://stackoverflow.com/questions/5396560/how-do-i-convert-special-utf-8-chars-to-their-iso-8859-1-equivalent-using-javasc thinking it's an encoding issue.
Hi, I'm developing a phonegap app with js and i need to print a logo and barcode. Are you working on this? or do you know any plugin that works and has image print support?
Once I connect printer and give print command, getting "service discovery failed". What could be the fix?
function list()
{
try
{
window.BTPrinter.list(function(data){
alert("Success");
alert(data); //list of printer in data array
},function(err){
alert("Error");
alert(err);
})
}
catch(e)
{
alert(e.message)
}
}
Always prompt for 'the cannot read property list undefined'
Hello Team,
after installing the plugin it not call in ionic2. Please let me know what i need to do.
Thanks
Deepak
if there is any option for selecting device type for our bluetooth printer plugin ? assume there a so any paired device in our mobile,then how can i select perticular bluetooth device to mobile . there is any option for that ? am waiting for your reply
Hi,
I am getting undefined for the variable BTPrinter in phonegap developer mobile app.
I installed the plugin correctly. bluetooth is not working in my laptop so i have to check by connecting with mobile. In laptop when i put console BTPrinter is having value. kindly help me plz.
The problem is occurring only when i am using developer mobile app.
BTPrinter.list(function(data){
console.log("Success");
console.log(data); \list of printer in data array
},function(err){
console.log("Error");
console.log(err);
})
regards,
I need a confirmation about following printer model . Do they work with this library ? or if any other printer.
SP-X501B is a thermal printer . SP-X501B
AGPtEK® 58mm Mini Bluetooth/USB Pocket POS Thermal Receipt Printer for Android IOS . Here
I need to use any one of above printer to print the order (Restaurant Management ).
In my project I needed a reliable isConnected() function, to test connection status and reconnect if needed, and as a workaround, I used this function that tries to print and, if not connected, tries to connect and print again. Thus, the connection to the device is made automatically. Tested on a cheap chinese bluetooth printer connected to an android device.
safePrint() {
let device = 'MTP-3';
let text = 'safe print ok\n\n';
this.safe_print_msg = 'printing text...';
setTimeout(() => {
BTPrinter.printText(data => {
this.safe_print_msg = 'print ok, already connected!';
}, err => {
this.safe_print_msg = 'print ERROR, connecting...';
setTimeout(() => {
BTPrinter.connect(data => {
this.safe_print_msg = this.msg = 'connected, printing again...';
setTimeout(() => {
BTPrinter.printText(data => {
this.safe_print_msg = 'print ok';
}, err => {
this.safe_print_msg = 'print_ERROR';
}, text);
}, 0);
}, err => {
this.safe_print_msg = this.msg = 'connect ERROR';
}, device);
}, 0);
}, text);
}, 0);
}
I can't use code , you have sample code.
Thank you
max
Can someone please upload an example to get this plugin to work in ionic.
My print function run twice and below is my codes.
Can somebody advice me?
var printerName = $rootScope.printerName;
var canvas = document.createElement("canvas");
JsBarcode(canvas, "88881ID1|60000", {format: "CODE128"});
$rootScope.barcode = canvas.toDataURL("image/png");
$scope.testPrint = function() {
BTPrinter.connect(function(data) {
BTPrinter.print(function(data) {
BTPrinter.disconnect(function(data) {
}, function(err) {
}, printerName);
}, function(err) {
}, $rootScope.barcode);
}, function(err) {
}, printerName);
};
i tried to print image with this plugin in ionic 1 and the result is nice as expected.
but when i tried to print image with this plugin in ionic 2, it print unknown character.
is it possible to print image in ionic 2 ?
thank you for this awesome plugin. keep up good work dude.
cordova plugin add https://github.com/srehanuddin/Cordova-Plugin-Bluetooth-Printer.git while performing this action i am getting this issue.
Error: Failed to fetch plugin https://github.com/srehanuddin/Cordova-Plugin-Bluetooth-Printer.git via registry.
Probably this is either a connection problem, or plugin spec is incorrect.
Check your connection and plugin name/version/URL.
How to resolve this issuecordova plugin add https://github.com/srehanuddin/Cordova-Plugin-Bluetooth-Printer.git while performing this action i am getting this issue.
Error: Failed to fetch plugin https://github.com/srehanuddin/Cordova-Plugin-Bluetooth-Printer.git via registry.
Probably this is either a connection problem, or plugin spec is incorrect.
Check your connection and plugin name/version/URL.
How to resolve this issue
Hey great plugin.
Kindly tell me how to print multiple lines. I've used \n but the printer simply ignores any text after the first \n it sees.
Thank you
Hi, I am quite new in this printing area.
May I know if there are any sample of printing using pos command using this plugin?
Thank you.
Hello!
I can get a list of connected blueetoth devices with BTPrinter.list
, but I don't know how to select one and use it for printing. I understand that I have to use BTPrinter.printText
function, but I suppose this must know which printer to use.
Hi I have this error: ** Error Print! bad base-64 **
I use that print image method in this plugin, this is my code:
function printerDocument(printParam) {
var tes='<div><img src="'+printParam.logo+'"/></div><br>';
BTPrinter.connect(function (data) {
console.log("Connected...");
console.log(data);
BTPrinter.print(function (data) {
console.log("Success");
console.log(data)
BTPrinter.disconnect(function (data) {
console.log("Success disconnected");
console.log(data)
}, function (err) {
console.log("Error");
console.log(err)
}, "WOOSIM");
}, function (err) {
console.log("Error Print!");
console.log(err)
},tes);
}, function (err) {
console.log("Error Connecting!!");
console.log(err);
}, "WOOSIM");
printParam.logo is a base64 image
printQrCode() {
const justify_center = '\x1B\x61\x01';
const justify_left = '\x1B\x61\x00';
const qr_model = '\x32'; // 31 or 32
const qr_size = '\x08'; // size
const qr_eclevel = '\x33'; // error correction level (30, 31, 32, 33 - higher)
const qr_data = 'http://stackoverflow.com/';
const qr_pL = String.fromCharCode((qr_data.length + 3) % 256);
const qr_pH = String.fromCharCode((qr_data.length + 3) / 256);
BTPrinter.printText(data => {
this.msg= 'QR code ok';
}, err => {
this.msg= 'QR code ERROR';
}, justify_center +
'\x1D\x28\x6B\x04\x00\x31\x41' + qr_model + '\x00' + // Select the model
'\x1D\x28\x6B\x03\x00\x31\x43' + qr_size + // Size of the model
'\x1D\x28\x6B\x03\x00\x31\x45' + qr_eclevel + // Set n for error correction
'\x1D\x28\x6B' + qr_pL + qr_pH + '\x31\x50\x30' + qr_data + // Store data
'\x1D\x28\x6B\x03\x00\x31\x51\x30' + // Print
'\n\n\n' +
justify_left);
}
Just Doesn't want to print ?
<script> function testing(){ BTPrinter.printText(function(data){ console.log("Success"); console.log(data); },function(err){ console.log("Error"); console.log(err); }, "Print" ); disconnect(); } </script><script>
function disconnect(){
BTPrinter.disconnect(function(data){
console.log("Success");
console.log(data);
},function(err){
console.log("Error");
console.log(err);
}, "C065120505");
}
</script>
Bluetooth print plugin working correctly in my phonegap app . but bluetooth printer not working . just connecting the device ,but nothg is printed . what will i do , need extra jar file to attach my app , please respond me
How to set width and height of barcode printing?
Hi, when i'm using the printText code snippet, i get the error "Invalid action".
Regards.
I have convert to html to base64 but how to print it using this plugin.
could you please give me step by step to use this plugin.
when connecting to the printer using the name returned by the List function it always returns:
Error
println needs a message
Is it possible to use this plugin via PhoneGap Build?
Example...
<plugin name="cordova-plugin-device" spec="1.1.2" />
<plugin name="....." spec="..." />
Hello
it's only providing the support on the android. Is there any supported features on ios ?
Thanks
Like this ,
BTPrinter.print(function(data){
console.log("Success");
console.log(data)
},function(err){
console.log("Error");
console.log(err)
}, "String1","String2")
am using this function to pass two parameters but its occur invalid action . is it possible for passing more than one parameter to this printing function .
Can anyone help me with an example of how to print barcode?
Or is it not possible?
Hey guys. I've been playing with this plugin since last night and faces some problem along the way. My initial setup connects to my bluetooth printer and send data to printer but doesnt print the text with no error log. Succeding test will also fail with error:read failed socket might blah blah.
Here's my solution, and this might help you as well.
I'll report back when i found something new, but right now my printer is working.
Thanks srehanuddin for the awesome plugin..one star for you brother.
Can anyone help me with an working sample of this plugin? i have tried to run the code after onDeviceReady but it doesnt show anything. also tried to write to console BTPrinter and window.BTPrinter but nothing would work. thanks
Hi srehanuddin, thanks for the awesome plugin! btw, can i change font style (bold, italic,etc) or fontsize?
regards,
When i want to printting i have error read failed, socket might closed or timeout, read ret: -1
anyone has same issue like me ? sometimes i must restart my bluetooth and printer device
My Code `$scope.printbtt = function(opr,noTelp,valueOpr){
console.log('Printer Start');
$scope.doc = "\n TESTING \n PULSA.1 \n KIOS SAYA \n Term : 10006062 \n Ref. No. Bank : 00000000050 \n PEMBELIAN VOUCHER \n "+opr+" \n No Hp : "+noTelp+" \n No. Seri : 0010101 \n Nominal : "+valueOpr+" \n \n \n ";
$scope.test = JSON.stringify($scope.doc);
console.log($scope.test);
BTPrinter.connect(function(data){
console.log(" Connected...");
console.log(data);
BTPrinter.printText(function(data){
console.log("Success print");
console.log(data)
BTPrinter.disconnect(function(data){
console.log("Success disconnected");
console.log(data)
},function(err){
console.log("Error disconnecting!");
console.log(err)
}, "WOOSIM");
},function(err){
console.log("Error Print!");
console.log(err)
}, $scope.test);
},function(err){
console.log("Error Connecting!!");
console.log(err);
alert(err);
}, "WOOSIM");
}` why cannot print my text ?
Any Option for selecting paired device in selectbox generated with bluetoothprinter.java , there are so any paired devices are available ,then can i selected printers. need to display selectbox for selecting devices.
Hello,
I am using Phonegap and console printed this information when I tried this plugin:
Uncaught ReferenceError: BTPrinter is not defined
But if I use cmd and check plugins: .go to app folder and type phonegap plugin list
I see: cordova-plugin-bluetooth-printer 0.0.1-dev "BluetoothPrinter"
Do you know where can be problem?
confix.xml:
<gap:plugin name="cordova-plugin-bluetooth-printer" />
Thank you!
I am trying to print some string using this plugin but I got error
When trying to go to BTPrint.printText
function, it gaves me invalid action
then I got Read failed, socket might closed or timeout, read ret: -1
after click the same button.
My code as follows;
$scope.connectPrinter = function(name) {
$scope.test = "\n Muahahahahah \n Muahahahahah \n Muahahahahah \n \n \n \n";
BTPrinter.connect(function(data) {
alert("Success");
alert(data);
BTPrinter.printText(function(data) {
alert("Success");
alert(data);
BTPrinter.disconnect(function(data) {
alert("Success");
alert(data);
}, function(err){
alert("Error");
alert(err);
}, "name")
}, function(err){
alert("Error");
alert(err)
}, $scope.test)
}, function(err){
alert("Error");
alert(err);
}, name)
};
Can anyone assist me?
I install the plugin at command line,But I don't know how to import it to ionic2 project
In the current state connection management is very difficult, the only connection things we have is connect, disconnect, and with a parameter also disconnect all.
However there's no way to tell if you're already connected, currently i have to try and catch a disconnect operation no matter what, even if it's the first connection (just to be safe).
In most parts of my code i have catch blocks that trigger a disconnect, connect again and retry the current operation.
As some of you could notice, this leads to some overhead because i have to call some functions many times even if it is not necessary, and yet errors still occurs.
Say i print, some times the connection breaks or something like that, then it tells me some errors, sometimes trying to print again fix the issue, other times i have to shut down the printer, close the app and open again in order to get rid of the issue.
Is it possible to create a function to check if the connection is OK?, not just open but that the data is actually being received by the printer (valid connection)?
I have been trying to use this plugin for some time now with little success.
Here is my controller
angular.module('starter.controllers', ['ionic', 'starter.controllers','ngCordova'])
.controller('PrintCtrl', function($scope, BTPrinter) {
BTPrinter.list(function(data){
console.log("Success");
console.log(data); //list of printer in data array
},function(err){
console.log("Error");
console.log(err);
})
})
I keep on getting this error message
Unknown provider: BTPrinterProvider <- BTPrinter <- PrintCtrl
Help!
How can use this plugin in config.xml file not by Using the Cordova CLI and NPM?
I added this line into my config.xml but got an error message on adobe phonegap builder;
<gap:plugin name="Cordova-Plugin-Bluetooth-Printer" source="npm" />
error message:
Error - The following plugin, plugin version or a dependancy of this plugin is not on npm: Cordova-Plugin-Bluetooth-Printer
Hai guys
I found a problem when connect to get the message 'println needs a message'
Please help
thank you
Hello,
Error log:
Cannot read property 'connect' of undefined
My code:
window.BTPrinter.connect(function(data){
alert("Success");
alert(data);
},function(err){
alert("Error");
alert(err);
}, "SPP-250")
Thank you!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.