Lenny Cunningham, created this handy Cloud Print Connector for Google Apps Script, using the library from EzyOauth2 – taking some pain out of Apps Script API authentication. For more contributions like these, why not join the Google Apps Script community.

Here is his guest post on his implementation.

Cloud Print Connector for GAS

I know I’ve been after a solution for this for quite some time. In the past have just used the e-mail address assigned with our HP printers to be able to programatically print. Issue is that there is not an email option for legacy printers connected through GCP in Chrome on a print server. ie “Shipping Label Printer”

Well here it is a Library for all of Google Cloud Print’s Service Interfaces.

Thanks to Bruce Mcpherson and his EzOauth2 Library it was a few simple steps to setup a GCP Connector Library.

Couple steps should get you printing in no time.

Step 1: Make a copy of this app script

Step 2: Follow EzOauth2Setup.gs file steps.
Based off Bruce’s EzyOauth2 Library.

All needed code is in the copied script, in the “EzOauth” file, just follow his directions on getting setup and the first authorization needed.

Step 3: Set the copied script as a Library Resource in other scripts, and you can submit a job to a printer like this.
CloudPrintLib.submit(printerid, title, ticket, content, optContentType, optTag)

That is an example of how to submit a job. There are methods for using all the available GCP service interfaces. Highly suggest reviewing their API documentation here. It documents all the required params, and responses of the methods.

Different documents might require different blob types, or print ticket settings, this following method prints a Google Doc file in color. This has been tested on an HP Cloud Ready Printer.

CloudPrintLib.submit(printerid, title, ticket, content, optContentType, optTag)

How to get a printerid

https://www.google.com/cloudprint/#printers/ah4e9pgysemvvhurllcwow Goto the printer, select details, then Advanced Details.

CloudPrintLib.search() will return all available printers and you can find printerid in there also.

Things to know:

“Content” for submit, depends on the blob type, the printer capabilities, many factors can affect whether it’s accepted or not. (Trial and error is your friend)

“Tickets” are the printers settings that you want use, (ie Color or Monochrome, Duplex, No_Duplex, Tray) print ticket is always required, but if you don’t submit one the default settings of the printer will be applied.

Not all printers have the same settings, so calling that printer with “CloudPrintLib.printer(printerid, optUse_cdd, optExtra_Fields) will return it’s “CDD” response with all it’s available settings.Troubleshooting: “Failed to parse print ticket or invalid print ticket”. The GCP Developer group provides a lot of information, and this post explains how to find out what your particular ticket needs to look like. You don’t need a mac, just send a successful print job, get that job id, and lookup the “CJT” response on the job lookup part of the simulate page.

If you’d like to make a guest post, contact me on the forum

For help and more information join our forum, follow the blog, follow me on Twitter