0

I am building a Cordova app which should allow us to print from mobile.

I am following this plugin

I have added the print code directly at device-ready, So on device ready I am allowed to select save as pdf and to search for printer, Till here every thing is working good my code in app.js

var printer = angular.module('starter', ['ionic','ngCordova'])

printer.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    cordova.plugins.printer.isAvailable(
    //Check whether the printer is available or not.
    function (isAvailable) {
         //Enter the page location.
         alert("printer is available")
         var page = location.href;
         cordova.plugins.printer.print(page, 'Document.html', function () {
         alert('printing finished or canceled')
});
    }
); 

So above code open the dialog to select printer here and even alerts the message that printer is available.

The main issue is when I select search printers, it continuously searches the printer but no reply till 15 minutes, there is no time-out there.I have a wifi printer connected through LAN.

I am just wondering that is there any specific settings on printers to print from android?

Any kind of suggestion and help will be appreciated.

Blu
  • 4,036
  • 6
  • 38
  • 65
Ajit Hogade
  • 1,072
  • 9
  • 29

1 Answers1

0

This is my code to use the printer. Be sure there's any printer service installed on your phone. The cordova plugin will call to that printer service, the the printer service will handle the printing job, not the plugin.

angular.module('app.services')
.factory('printService', function() {

    return {
        print: function(printingContent){

            var receipt ='<html>Hello</html>';

            cordova.plugins.printer.check(function (avail, count) {
                if(avail == true){
                    cordova.plugins.printer.pick(function (uri) {
                        //alert("Printer pick: " + uri);
                        cordova.plugins.printer.print(receipt, { duplex: 'long' }, function (res) {
                            alert(res ? 'Printing Done' : 'Printing Canceled');
                        });
                    });
                }                       
                else
                    alert('No printer service found');
            });

        }
    }
})