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: 613
  • CloudPrint_Lib_2.0.zip
    4.2 KB · Views: 665
Last edited:

johndb

Active Member
Licensed User
Longtime User
Thank you .... Thank you .... NJDude!!!!! The update works very well!!
 

tdocs2

Well-Known Member
Licensed User
Longtime User
Congratulations, NJ.

I thought the JAVA had you stopped. WOW.

Sandy
 

tdocs2

Well-Known Member
Licensed User
Longtime User
Thank you, NJ, for this breakthrough.

I tested the app and lib with 4.2 and 5.0 and it works. I sent an xls (Erel's movie xls) and it also printed it.

The preview is not very useful. It allows for choice of ANY NUMBER OF copies and choice of monochrome and Grey_CMY.

It does not provide a real preview of the document to be printed. Also, it does not provide for choice of landscape or portrait, etc.

Is the Preview under your control?

Best regards.

Sandy

Edit: ANY NUMBER OF (originally I indicated 1 or 2 - the scrolldown list was a little awkward and I did not see it).. I could not find the strikethrough in the Editor.
 
Last edited:

johndb

Active Member
Licensed User
Longtime User
Thank you, NJ, for this breakthrough.

I tested the app and lib with 4.2 and 5.0 and it works. I sent an xls (Erel's movie xls) and it also printed it.

The preview is not very useful. It allows for choice of 1 or 2 copies and choice of monochrome and Grey_CMY. It does not provide a real preview of the document to be printed. Also, it does not provide for choice of landscape or portrait, etc.

Is the Preview under your control?

Best regards.

Sandy

I can select any number of copies, colour/monochrome, portrait/landscape, .... etc. I think it may be a function of the printer driver but it is working fine for me. I do not think it ever provided a real preview of the document as it only shows the mode you have selected select.

Cheers,

John
 
Last edited:

tdocs2

Well-Known Member
Licensed User
Longtime User
Thank you, John.

I edited my comment to reflect that multiple number of copies (awkward drop down list) are available. I only have one Cloud Printer (HP).

Sandy
 

Mahares

Expert
Licensed User
Longtime User
I was not able to print text files with the .tab or .csv extension thanks to an 'unrecognized file type' message. My workaround was to copy the file with the extension .tab to a .txt file and print it that way. Has anyone else experienced the same issue I had. I can, however, print a .tab file going through Cloud Print app without using NJDude's library.
 

tdocs2

Well-Known Member
Licensed User
Longtime User
Hello, Mahares.

See my post above...

I tested the app and lib with 4.2 and 5.0 and it works. I sent an xls (Erel's movie xls) and it also printed it.
The preview is not very useful. It allows for choice of ANY NUMBER OF copies and choice of monochrome and Grey_CMY.
It does not provide a real preview of the document to be printed. Also, it does not provide for choice of landscape or portrait, etc.

I have not tried to print a csv, but obviously, it would work with a .txt. I have no ide of what a tab is.

Maybe, we can both encourage NJ to enhance the library for an effective preview like in WPS Office - (specially critical is the choice of landscape or portrait) and print additional formats (if the Google Print allows it). But I know JAVA is a killer....

I am amazed that this thread does not have 300 posts and 300 likes! Printing in Android is a very desirable feature.

Best regards, Mahares, and once again, thank you, NJ. I would give you a double like! However, the inability to set Orientation is a show stopper for me. And JAVA is coffee to me. I have enough contending with VB and B4A.

Sandy

PS: I also made the request to Erel via a wish for a B4A Print Library. And also requested Klaus for a Print Function for the Flexible Table Class (Klaus said he had no experience in this area.)
 

Mahares

Expert
Licensed User
Longtime User
Thank you @tdocs2 (Sandy) for your input and interest in this good and useful library from the great NJDude aka USADude to me. I can print .xls and .txt files but not .csv and .tab files. A .tab file is simply a text file where the delimiter of the items is a TAB instead of a COMMA. It is a great alternative to files that have commas in the items because it is easier to parse. I am sure we will hear from NJ/USA Dude.
 

NJDude

Expert
Licensed User
Longtime User
The functionality of this library depends on what Google allows/provide and of course, the printer's capabilities, I have no problem setting the orientation, resolution, number of copies etc on my printer via this library.
 
Last edited:

tdocs2

Well-Known Member
Licensed User
Longtime User
Thank you, NJ.

I attach two screenshots of the settings I get from the HP LaserJet Professional M1217 from CloudPrint and from WPS. My WISH would be for CloudPrint to offer the WPS capability even in more limited fashion. And I can get a full preview with the WPS setting.

The file I was printing was Erel's Movie xls.

Best regards.

Sandy

CloudPrintPrintSettings.png WPSPrintSettings.png
 

tdocs2

Well-Known Member
Licensed User
Longtime User
Thank you again, NJ.

I am trying to figure out the Print Service behavior. The post above, I ran on a Samsung Note 4.4.

This time, I am running on an Asus TF103 4.4 also. Both Google and HP print Services are installed. I got this error (please see png) and Printing Settings.

Sandy

ErrorManifestFile.png printing Settings.png
 

tdocs2

Well-Known Member
Licensed User
Longtime User
Hello, NJ.

I got an inexpensive Samsung Laser ($69) at amazon for my testing.

I printed the famous Erel's Movie xls. The HP printer does NOT give Orientation. The Samsung does.

Device Nexus 10 5.0 and Matricom (TV box with Google Launcher) 4.4

Best regards.

Sandy

1Android5.png 2HP.png 3Samsung.png
 
Last edited:

tdocs2

Well-Known Member
Licensed User
Longtime User
Hello, again.

I am not trying to win a prize for most posts under this thread. I am just very interested in printing from Android (as I think everyone should be - there should be 500 posts in this thread. JAVA is coffee to me).

I tried the same app I did on an ASUS TF103 running 4.4.2 and I got the same error I posted above - B4a v4, Windows 8.1, Lib v 1.5 latest, SDK up to date.

Any ideas? Any help?

Thanks.

Sandy

Asus Error.png
 
Last edited:

tdocs2

Well-Known Member
Licensed User
Longtime User
NJ,

I did, but to make sure, I renamed the CloudPrint app I had, downloaded the one in post 1 a minute ago.

Same error.

Both the one I had and the one I just downloaded had the same manifest file and

B4X:
#Region  Project Attributes
    #ApplicationLabel: CloudPrint Lib Sample
    #VersionCode: 1
    #VersionName: 1.0
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

Any thoughts? The error message indicates a manifest declaration missing. But then why does it not happen in all the other devices? The TF103 is the "latest" from ASUS.

Thank you for looking into this.

Sandy

PS: On my Settings>Printing Cloud Print is On
 

NJDude

Expert
Licensed User
Longtime User
If it happens only on the ASUS it means it's the device, it seems it doesn't have the latest CloudPrint installed, I have a device myself running 4.4.2 and it works like a charm.

I will have to "patch" the library to fix that issue.
 
Top