Page 4 of 6

How to do print currnt page when click on Print button.

Posted: Mon Apr 28, 2014 1:41 pm
by Asif

Hi Katya,
As you said i have written given below code
code
// Get HTML string
var page = document.body.innerHTML;

// Pass the HTML
window.plugin.print(page);
/code

But still i m getting same error :
Uncaught TypeError: Cannot read property 'print' of undefined.

Pls help


How to do print currnt page when click on Print button.

Posted: Mon Apr 28, 2014 5:08 pm
by Maryna Brodina

Hello!

Have you tried to build apk application and test your code on device ?


How to do print currnt page when click on Print button.

Posted: Mon Apr 28, 2014 6:40 pm
by Asif

Yes Maryna,
I have tried the app from the device as .apl file, i got following error

code
04-29 00:00:40.218: D/CordovaLog(14938): file:///android_asset/www/files/resources/lib/plugins/com.phonegap.plugins.printer/www/printer.js: Line 66 : Uncaught ReferenceError: module is not defined
04-29 00:00:40.218: E/Web Console(14938): Uncaught ReferenceError: module is not defined:66
04-29 00:00:40.328: D/CordovaActivity(14938): onMessage(spinner,stop)
04-29 00:00:40.368: D/CordovaNetworkManager(14938): Connection Type: 3g
04-29 00:00:40.368: D/CordovaNetworkManager(14938): Connection Type: 3g
04-29 00:00:40.378: D/CordovaActivity(14938): onMessage(networkconnection,3g)
04-29 00:00:48.446: D/webview(14938): blockWebkitViewMessage= false
04-29 00:01:19.518: D/webview(14938): blockWebkitViewMessage= false

/code

on line no 66 in printer.js following code is present
code

module.exports = plugin;

/code


How to do print currnt page when click on Print button.

Posted: Tue Apr 29, 2014 6:18 am
by Kateryna Grynko

Hi Asif,

This error is in the file "printer.js" which is a 3rd party plug-in. Unfortunately, third party plugins are out of scope of our support. You would need to fix the error or you could try to use this plugin with this error.


How to do print currnt page when click on Print button.

Posted: Tue Apr 29, 2014 8:12 am
by Kateryna Grynko

Asif,

Let's try to define your Cordova Plugin As A Cordova Module.
Let's look at org.apache.cordova.core.battery-status module in Appery.io.
A name in "clobbers" field of cordova_plugin.js is a name of reference to your module. For example, if we have such lines in cordova_plugin.js
pre{
"file": "plugins\com.phonegap.plugins.printer\www\printer.js",
"id": "com.phonegap.plugins.printer.Printer",
"clobbers": [
"Printer"
]
}/preAfter that, we should use such code to access the plugin: prePrinter.print(page);/pre


How to do print currnt page when click on Print button.

Posted: Tue Apr 29, 2014 11:03 am
by Asif

Hi Katya,
I have already made an entry of Printer plugin in cordova_plugin.js like you said.
And now when I am writing given below code
code
Printer.print(page)
/code

i m getting this error:
code
04-29 16:26:00.690: D/CordovaLog(6065): file:///android_asset/www/ipadscreen1.js: Line 369 : Uncaught TypeError: Object function () {
04-29 16:26:00.690: D/CordovaLog(6065): } has no method 'print'
04-29 16:26:00.690: E/Web Console(6065): Uncaught TypeError: Object function () {
04-29 16:26:00.690: E/Web Console(6065): } has no method 'print':369
04-29 16:27:00.400: D/CordovaActivity(6065): Paused the application!
04-29 16:27:00.400: D/CordovaWebView(6065): Handle the pause
04-29 16:27:00.400: D/WebView(6065): loadUrlImpl: called
/code

I dont think there is any problem with the plugin, its just that i m not getting the way to use it with appery.
Can you please try to run the plugin once from my app. It would be a great help.


How to do print currnt page when click on Print button.

Posted: Tue Apr 29, 2014 3:24 pm
by Kateryna Grynko

Hi Asif,

You should also "wrap" printer.js like a Cordova module.

Here is a pattern for such wrapping:
precordova.define("com.phonegap.plugins.printer.Printer", function(require, exports, module) {
var cordova = require('cordova'),
exec = require('cordova/exec');
........
//here paste a body of your plugin
..........
});/pre


How to do print currnt page when click on Print button.

Posted: Wed Apr 30, 2014 8:33 am
by Asif

Hi Katya,
Do you mean to say that my printer.js will look like this ::

code
cordova.define("com.phonegap.plugins.printer.Printer", function(require, exports, module) {
var cordova = require('cordova'),
exec = require('cordova/exec');
........
//here comes the whole content of printer.js ??
..........
});
/code


How to do print currnt page when click on Print button.

Posted: Wed Apr 30, 2014 2:34 pm
by Asif

Hi Katya,
As you said i have wrapped printer.js and now i m calling print function as follows:

code
var page = document.body.innerHTML;
Printer.print(page);
/code
and now i m getting this error
code
04-30 19:59:36.484: D/CordovaLog(10990): file:///android_asset/www/ipadscreen1.js: Line 368 : Uncaught ReferenceError: Printer is not defined
04-30 19:59:36.484: E/Web Console(10990): Uncaught ReferenceError: Printer is not defined:368

/code


How to do print currnt page when click on Print button.

Posted: Wed Apr 30, 2014 5:49 pm
by Evgene Karachevtsev

Hello,

Correct cordova_plugins.js regarding printer plugin(pay attention to id)

code{
"file": "plugins\com.phonegap.plugins.printer\www\printer.js",
"id": "com.phonegap.plugins.printer.Printer",
"clobbers": [
"Printer"
]
}

/code