Kartiikeya
Kartiikeya

Reputation: 2516

Access printer from ionic2

I would like to know. is there any option to implement Print/connect printer from ionic 2 .Is there any cordova plugin to Print . I came across this plugin.

Cordova Print plugin

any help/Info regarding this will be useful.Is there any way to access third party libraries in Ionic 2.??

Upvotes: 2

Views: 2082

Answers (2)

Ahmed Bouchefra
Ahmed Bouchefra

Reputation: 256

In Ionic 2 you can use Ionic Native with the Cordova printer plugin to print either to a PDF file or to a real paper .The steps to follow are easy . First add the Cordova plugin for printing with

cordova plugin add https://github.com/katzer/cordova-plugin-printer.git

Next import classes

import {Printer, PrintOptions} from 'ionic-native';

Then add this method to your class

    print(){

        Printer.isAvailable().then(function(){
            Printer.print("https://www.techiediaries.com").then(function(){
            alert("printing done successfully !");
            },function(){
            alert("Error while printing !");
            });
        }, function(){
        alert('Error : printing is unavailable on your device ');
        });

}

To test the method add a button to your template

       <button class="button" (click)="print()">Print</button>

You can find the complete tutorial here

Upvotes: 1

Ajith K P
Ajith K P

Reputation: 396

Cordova Print Plugin ,

cordova plugin add cordova-plugin-printer

cordova plugin add cordova-plugin-printer Or a specific version:

cordova plugin add cordova-plugin-printer@VERSION

And then execute:

cordova build

https://github.com/katzer/cordova-plugin-printer

Upvotes: 0

Related Questions