Asif
Posts: 0
Joined: Tue Aug 13, 2013 12:56 pm

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

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

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

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

Hello!

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

Asif
Posts: 0
Joined: Tue Aug 13, 2013 12:56 pm

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

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

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

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

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.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

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

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

Asif
Posts: 0
Joined: Tue Aug 13, 2013 12:56 pm

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

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.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

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

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

Asif
Posts: 0
Joined: Tue Aug 13, 2013 12:56 pm

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

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

Asif
Posts: 0
Joined: Tue Aug 13, 2013 12:56 pm

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

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

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

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

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

Return to “Issues”