2

I'm working on a simple phonegap app that prints a simple pdf page to test Google cloud printing, I followed steps mentioned here.
It's working fine in a browser but when I tried it on a mobile, nothing was printed, I wasn't even able to save it to my Google drive.
Here is my code:

var gadget = new cloudprint.Gadget();
gadget.setPrintDocument("url", "Test Page",
       "http://www.google.com/landing/cloudprint/testpage.pdf");
gadget.openPrintDialog();
mmmmmm
  • 32,227
  • 27
  • 88
  • 117
Mohamed Salah
  • 1,506
  • 1
  • 14
  • 23

2 Answers2

2

I faced this issue too, it can be solved using a simple http request. at first you have to add InAppBrowser, then you can use this plugin for printing, it supports Google Cloud Print on Android and AirPrint on iOS

after adding printing plugin, it can be used as below:

var type = "text/html"
var title = "test.html";
var fileContent = "<html>Phonegap Print Plugin</html>";
window.PrintPlugin.print(fileContent,function(){console.log('success')},function(){console.log('fail')},"",type,title);
Hazem Hagrass
  • 9,329
  • 10
  • 32
  • 54
  • 1
    Device plugin (http://docs.phonegap.com/en/3.0.0/cordova_device_device.md.html#Device) is also needed for your plugin to work. Thanks for your plugin – janot Nov 13 '13 at 17:02
  • Dear Hazem Hagrass I am very new to this phonegap. Please guide me the process. I am searching for this for a long time. – Saikat Apr 09 '14 at 05:35
  • @Saikat: just open the plugin page on github and you will find the steps – Hazem Hagrass Apr 09 '14 at 08:58
  • @Hazem Hagress: I downlod the zip file and make a app of that. Open that app in tablet. Can see the Print button also. But nothing happens when i press the Print button. I am so confused. How to exactly make the printer work. I have already connect a printer to could. But can't open it through an app. – Saikat Apr 09 '14 at 10:15
  • @Saikat just add device plugin first via phonegap cli: "cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git" – Hazem Hagrass Apr 09 '14 at 12:58
  • @Hazem Hagress: As you know I am very new to this phone gap. So please tell me the process in details. Thanks in advance. – Saikat Apr 10 '14 at 05:38
  • @Hazem Hagress: Will you please make a little prototype of it and help me to understand the process. – Saikat Apr 10 '14 at 05:53
  • Dear @HazemHagrass, the asker has posted an example of printing a pdf file.
    The plugin you proposed allows printing pdf or text/html documents only?
    – T. Phanelly Jan 13 '15 at 11:55
  • I have a same problem but i did not use phonegap, I am using free service from web to convert my web app into android app. Before converting everything working good but after converting to apk file. google cloud print not working. if there is any solution for that? – Karthi Mar 03 '17 at 10:09
1

at first it didn't work with me then I added Device plugin to make it work.