B4A Library CloudPrint - Library

This library will allow you to add printing capabilities to your apps using CloudPrint.

This is an alternative solution to the one on THIS post.

Requirements:

1- A printer connected to CloudPrint, see the setup instructions HERE.

2- The CloudPrint app installed on your device.

3- Copy the CloudPrint.xml and CloudPrint.jar to your additional libraries directory.

Usage:
B4X:
'Initialize the library
Private print As CloudPrint

print.Initialize

'To print a document do this:
print.SendToCloudPrint("Test file", File.DirDefaultExternal, "Sample_Document.txt")

'To print a website
print.SendWebViewToCloudPrint("My Website", WebView1)

'To see your print queue
print.ShowPrintJobs

That's it!!

NOTES:

* This lib is not compatible with KitKat (KitKat has printing built in but I've been unable to get it to work, stay tuned).

* You CANNOT print documents saved on DirAssets, DirInternal or DirInternalCache.

* Make sure you have the most current CloudPrint app installed.

A sample project is attached.

Thank you.
 

Attachments

  • CloudPrint_Lib_Sample.zip
    10.2 KB · Views: 621
  • CloudPrint_Lib_2.0.zip
    4.2 KB · Views: 677
Last edited:

le_toubib

Active Member
Licensed User
Longtime User
All right i retried it with another printer, and it did the same, countless printed copies from the same job came out of the machine.
I have no loops in my sub, just a simple button click to print.
 

schemer

Active Member
Licensed User
Longtime User
Ok, got it! Sort of...It only took 4 hours to get it all figured out. :eek: Hope the end users of my app will be able to do better or I am hosed. :confused: At least I know how to get it set up. Anyhow, I am only able to print the web page from the phone and not the Sample_Document.txt that is in the example. Am I supposed to be putting that somewhere else or is it supposed to work out of the box? The code says:

B4X:
                'the directory CANNOT be DirAssets, DirInternal or DirInternalCache
                'The DocumentTitle is optional
                print.SendToCloudPrint("Test file", File.DirDefaultExternal, "Sample_Document.txt")

Thanks,
schemer
 

NJDude

Expert
Licensed User
Longtime User
Ok, got it! Sort of...It only took 4 hours to get it all figured out. :eek: Hope the end users of my app will be able to do better or I am hosed. :confused: At least I know how to get it set up. Anyhow, I am only able to print the web page from the phone and not the Sample_Document.txt that is in the example. Am I supposed to be putting that somewhere else or is it supposed to work out of the box? The code says:

B4X:
                'the directory CANNOT be DirAssets, DirInternal or DirInternalCache
                'The DocumentTitle is optional
                print.SendToCloudPrint("Test file", File.DirDefaultExternal, "Sample_Document.txt")

Thanks,
schemer
Like the example explains, you have to have the files you want to print on DirDefaultExternal (or RootExternal)
 

schemer

Active Member
Licensed User
Longtime User
Like the example explains, you have to have the files you want to print on DirDefaultExternal (or RootExternal)

I missed the "RootExternal" part. :rolleyes: It so happens my phone has no external sd card option. And the table I bought (Nexus 7 in the mail) doesn't either. I made another post to get some more options.
Thanks,
schemer
 

NJDude

Expert
Licensed User
Longtime User
All systems have external storage, the Nexus 7 does too, you are mistaking the internal SD Card with an external SD Card.

External SD Cards are not really supported by Android.
 

schemer

Active Member
Licensed User
Longtime User
All systems have external storage, the Nexus 7 does too, you are mistaking the internal SD Card with an external SD Card.

External SD Cards are not really supported by Android.

That is good to know. So why didn't the test.txt file print when using dirDefault External? My Droid RAZR MAXX HD only has 32 GB internal storage.
Thanks,
schemer
 

schemer

Active Member
Licensed User
Longtime User
If you look closely at the sample, the .txt file is in DirAssets and COPIED to DirDefaultExternal and then printed from there, are you doing that?.

Yes, the text file is in the FILES folder and the code was left as is and it does not print from the cloud printer, but the web page does.
schemer
 

schemer

Active Member
Licensed User
Longtime User
I just ran the sample attached on the first port, I have no issues whatsoever.

I just retested and it works with "both" the "Default" and the "Root". Sorry, I am a noob. :p I guess what happened was I fried my brain getting the cloud printer set up yesterday and did something wrong. I have a few Google accounts and had the printer setup on the pc account at first. Probably just me being new at all this. I am glad I got it working for sure. Great library. :)
Thanks,
schemer
 

schemer

Active Member
Licensed User
Longtime User
Are we able to print a webview with this yet? I was reading the original thread on the CloudPrint utility and am not sure if that was ever resolved. My next question, seeing I have never done it, is can we send the data from our app to a DirDefaultExternal (or Root) in the form of an .html file and print it from the cloud? I know html ok but never used it as a container for output before but I think it would work great in my app. Any examples that show sending outputs like text from editText or labels or lists, to html?
Thanks,
schemer

p.s. For the guy that wonders why there isn't 500 posts in this thread. I am working on it. :)
 

schemer

Active Member
Licensed User
Longtime User
The library works fine printing documents or websites just like the sample illustrates, if for some reason doesn't work then it means the developer is doing something wrong.

Ok, so that means if I can make and save an html file from my app to DirDefaultExternal , it can be printed as a file with cloud print? Not the source, but the rendered view?
Thanks,
schemer
 

schemer

Active Member
Licensed User
Longtime User
If you want to do that yes, you will have to create the HTML, save it on DirDefaultExternal then load it to a webview and print it.

Ok great, I was reading that the webview printing did not work in the past so I wanted to be sure it will.
Thanks again,
schemer
 

Blue.Sky

Active Member
Licensed User
Longtime User
Hi
How work this library?how print?
 
Top