Coder Social home page Coder Social logo

bookmebus / cordova-plugin-thermal-bluetooth-printer Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 1.0 20.19 MB

Cordova plugin for thermal bluetooth printer in iOS

Objective-C 79.15% JavaScript 10.51% Batchfile 1.90% Shell 0.65% CSS 2.78% HTML 2.87% Java 2.14%

cordova-plugin-thermal-bluetooth-printer's Introduction

Cordova-Plugin-Bluetooth-Printer for iOS

A Cordova plugin for thermal bluetooth printer for iOS platform which complements an excellent plugin from https://github.com/srehanuddin/Cordova-Plugin-Bluetooth-Printer that only support Android platform If you need to print in both Android and iOS you might have to use both plugins.

Support

  • Text
  • Image Printing (todo)

Example of usage

$('#btn-connect')[0].disabled = true
$('#btn-print-text')[0].disabled = true
$('#btn-print-image')[0].disabled = true

$('#btn-scan').on('click', function() {
  BmbBluetoothPrinter.scanPrinter(function(result) {
    console.log("==== Returned printers ==== ", result)
    printerManager.renderDevices(result)
  }, null)
})

$("#btn-print-text").on('click', function() {
  var string = "Test printing text"
  BmbBluetoothPrinter.printText(string, null, null)
})

$("#btn-print-image").on('click', function() {
  var $canvasContent = $("#canvas-content")[0]
  html2canvas($canvasContent, { useCORS: true }).then(function(canvas) {
    var base64 = canvas.toDataURL("image/png")
    base64 = base64.replace(/^data:image\/(png|jpg);base64,/, "");
    console.log("canvas == ", base64)
    BmbBluetoothPrinter.printImage(base64, null, null)
  });
})

$(document.body).delegate('.btn-connect', 'click', function() {
  var index = $(this).data("index")
  console.log("Index == ", index)
  BmbBluetoothPrinter.connectPrinter(index, function(response) {
    console.log("connect success ====")
    $('#btn-print-text')[0].disabled = false
    $('#btn-print-image')[0].disabled = false
   }, null)
})

var printerManager = {
  renderDevices: function (result) {
    var $deviceContainer = $('#device-container')
    var template = $("#device-item").text()
  
    var html = []
    for(var i=0;i<result.length; i++) {
      var name = result[i].split("|")[0]
      var uuid = result[i].split("|")[1]
      $.tmpl( template, { "name": name, "uuid": uuid, "index": i}).appendTo($deviceContainer)
    }

   if(result.length > 0) 
     $('#btn-connect')[0].disabled = false
  }
}

Example app

You can find cordova example app for quick demo and testing in DemoApp sub directory: https://github.com/bookmebus/cordova-plugin-bluetooth-printer/tree/master/DemoApp.

Contribution

We have no background in Objective-C we are thrilled to do it. In just two days we have it working. The code is not perfect yet but we are looking for contributors to solve this printing issue and open source it to empower others. Please hand up!

cordova-plugin-thermal-bluetooth-printer's People

Contributors

bookmebus avatar channainfo avatar limkimsan avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

channainfo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.