If you're using Ionic 2, you have the option to leverage Ionic Native along with the Cordova printer plugin to easily print documents, whether it be to a PDF file or a physical paper. The process is straightforward and simple.
Begin by adding the Cordova plugin for printing by running the following command:
cordova plugin add https://github.com/katzer/cordova-plugin-printer.git
Afterwards, import the necessary classes like so:
import {Printer, PrintOptions} from 'ionic-native';
Then include this method within your class:
print(){
Printer.isAvailable().then(function(){
Printer.print("https://www.techiediaries.com").then(function(){
alert("Printing completed successfully!");
},function(){
alert("Error occurred while trying to print.");
});
}, function(){
alert('Error: Printing is not available on your device.');
});
}
To test out the functionality, simply add a button component to your template:
<button class="button" (click)="print()">Print</button>
You can access the full tutorial here