@ionic-native/printer not working


#1

I have added the plugin as explained in the documentation. Printer plugin . Also, added the Printer provider in app.module.ts
Now when I call the printer plugin, it does not open the print preview window. The code is as follows:

this.printer.isAvailable().then(function(){
	      this.printer.print(content, options).then(function(){
	          console.log("Done!");
	      }, function(error){
	          console.log("Error while printing!");
	      });
	    }, function(error){
	          console.log("Failed.")
	    });

This is my ionic info:

Cordova CLI: 6.5.0 
Ionic CLI Version: 2.2.2
Ionic App Lib Version: 2.2.1
ios-deploy version: 1.9.1 
ios-sim version: 5.0.13 
OS: macOS Sierra
Node Version: v6.10.2
Xcode version: Xcode 8.3.2 Build version 8E2002

#2

What does it do instead? Do you get an error message?


#3

Thank you for your response. And, I am not getting any error message. Looks like the plugin isn’t responding .


#4

Hi @aspiringuserapps

Can you add screenshot of the error,So i can try to solve them.and you can also write the error

Thanks


#5

Thanks @vd_virani for your help. Attaching the screenshot.
This the the log :

This is the print code:

  • menu.ts file
 print(option){
		let content = '';
		if(option == 'all'){
			content = AppGeneral.getAllHTMLContent(this.msc);
		}
		else{
			content = AppGeneral.getCurrentHTMLContent();
		}

		let options: PrintOptions = {
			name: APP_NAME+'.html',
			duplex: false,
			landscape: false,
			grayscale: true
		};
		alert("print");

	    this.printer.isAvailable().then(function(){
	      this.printer.print(content, options).then(function(){
	          console.log("Done!");
	      }, function(error){
	          console.log("Error while printing!");
	      });
	    }, function(error){
	          console.log("Failed.")
	    });
	}
  • menu.html file
<button ion-item detail-none (click)="print('current')"><ion-icon name="print"></ion-icon>&nbsp;&nbsp;&nbsp;Print</button>