Skip to content Skip to sidebar Skip to footer

How To Imlement Print On Android Using Cordova?

I want to implement print functionality in Android app, I'm using AngularJS. I have tried the below code, but it works only on browser, it doesn't work on Android. AngularJS: $scop

Solution 1:

I also had the same issue. Try to do it using cordova-plugin-printer plugin. It will solve your problem. From your code it looks you want to print div by id. Below are various usage of above plugin:

Print the whole HTML page:

var page = location.href;

cordova.plugins.printer.print(page, 'Document.html');

Print the content from one part of the page:

var page = document.getElementById('legal-notice');

cordova.plugins.printer.print(page, 'Document.html');

Print some custom content:

var page = '<h1>Hello Document</h1>';

cordova.plugins.printer.print(page, 'Document.html');

For more options, check out the documentation : https://github.com/katzer/cordova-plugin-printer#usage

Solution 2:

It works for me in javascript

var dowloadurl  = "/.../sample.pdf"// Here your file locationwindow.cordova.plugins.FileOpener.openFile(
   dowloadurl,
   onSuccessFileOpen,
   onErrorFileOpen
);
    
var onSuccessFileOpen = function (data) {
    alert('onSuccessFileOpen');
};

functiononErrorFileOpen(err) {
    alert('message: ' + err);
}

Post a Comment for "How To Imlement Print On Android Using Cordova?"