Printer plugin not working


#1

Hello everyone,

The plugin located here seems to not work for me on android and ios : http://ionicframework.com/docs/native/printer/
I think that I followed the guidelines from this page, the code is building on both platforms but I got a black screen on ios and a blank one on android when emulate …

First I started a new project : ionic start PrinterApp --v2

Then I installed platforms : android 6.2.1, ios 4.3.1

Then the two command lines from the plugin page :

ionic plugin add --save de.appplant.cordova.plugin.printer
npm install --save @ionic-native/printer

Then in the home.html I put a line to active the printer :
<button class="button" (click)="print()">Print</button>

And finally my home.ts looks like this :

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Printer, PrintOptions } from '@ionic-native/printer';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  constructor(public navCtrl: NavController, private printer: Printer) {
  }

  print() {
  	 this.printer.isAvailable();
	let options: PrintOptions = {
	     name: 'MyDocument',
	     duplex: true,
	     landscape: true,
	     grayscale: true
	   };
	this.printer.print("http://google.com", options);
  }
}

Did anyone have this kind of troubles with the plugin ? Did I do something wrong ? Should I install other things to fix the problem ?
And did anyone have a exemple project working well ?

Thank you very much !


#2

Did you remote debug the problem on the device already?
Follow these instructions here to debug the problem in Safari dev tools: https://ionic.zone/debug/remote-debug-your-app#ios
Follow these instructions here to debug the problem in Chrome dev tools: https://ionic.zone/debug/remote-debug-your-app#android
Look at the console and network tabs for errors.


#3

Hello,

Thank you for the respond,
I tried, but no errors printed on the safari inspector,
I will try the chrome one this afternoon,

The code seems to be ok for you ?

Thanks again


#4

Did you also do http://ionicframework.com/docs/native/#Add_Plugins_to_Your_App_Module?

This doesn’t do anything, look at the docs how this works.


#5

Ok I will let you know after editing my code,
Thank you very much !


#6

Hello again,

I tried to remove almost everything to see where the problem came from so :

  • I fully removed the button from the html page
  • I fully removed the print function in my TS file

but I still have the problem (black screen on ios for exemple with no errors displayed on inspectors) so it should be a trouble with the call of :
import { Printer, PrintOptions } from '@ionic-native/printer';
or with the call in constructor with :
private printer: Printer

Do you have any guess ?

Thank you


#7

But you did what it says on http://ionicframework.com/docs/native/#Add_Plugins_to_Your_App_Module?


#8

Oh I didn’t understood well your point, I thought you send me this link to add :
npm install @ionic-native/core --save

but it was also for the provider part …

So : I added Printer in the provider part

It’s working ! :slight_smile:

Thanks Sujan, have a good day


#9

Hi,
I have encountered the same error that printer available check failed. Did you finally fix your problem? Can you offer some help?