Anybody that ever wanted to do unattended printing from the browser knows that's not an easy task and on the other hand it is something very useful for any back-office application. Then Google came to save us with GCP.
So I got it setup and in a few minutes I had a document printed. But then I wanted to apply some settings to the printer. And this is the moment you realise the documentation is completely lacking on this. It's not even explained how to do something as simple as setting the page to landscape.
The documentation only says that you have to send a capabilities parameter in XPS or PPD format. Even if you are able to retrieve the capabilities of your printer you realise that as its name suggests it describes all the printer capabilities and not the settings for a particular print job.
So how do you actually specify the print job settings?
After locating a page to print, click the three vertical dots in the top right corner of Chrome to generate a drop-down menu with options and settings controls. Click "Print" to open the printer settings. You can reach the same printer settings menu by selecting "Ctrl+p" on your keyboard, according to Google Support.
First of all the GCP documentation incorrectly states that you can retrieve the printer capabilities with the /list service interface. That doesn't work. You have to call the /printer service which does return the printer capabilities. The capabilities are simply a list of JSONs each describing a printer parameter and the possible values that parameter can take. Sometimes it can contain some additional information as well. Here is for example a small extract of the page sizes supported by my HP:
"name": "psk:PageMediaSize",
"psf:SelectionType": "psk:PickOne",
"psk:DisplayName": "Paper Size",
"type": "Feature",
"options": [
{
"psk:MediaSizeWidth": "215900",
"name": "psk:NorthAmericaLetter",
"psk:MediaSizeHeight": "279400",
"psk:DisplayName": "Letter"
},
{
"psk:MediaSizeWidth": "215900",
"name": "psk:NorthAmericaLegal",
"psk:MediaSizeHeight": "355600",
"psk:DisplayName": "Legal"
}
]
By looking at the POST request that Chrome sends from the GCP dialog I have found out that the /submit service does not use a capabilities parameter at all. It actually uses the parameter called ticket to specify the print job settings. The format of the parameter is quite simple, it is a JSON that looks like this:
{
"version":"1.0",
"print":{
"color":{"vendor_id":"psk:Color","type":0},
"duplex":{"type":0},
"page_orientation":{"type":1},
"copies":{"copies":1},
"dpi":{"horizontal_dpi":600,"vertical_dpi":600},
"media_size":{"width_microns":148000,"height_microns":210000,"is_continuous_feed":false},
"collate":{"collate":true},
"vendor_ticket_item":[
//Printer specific settings here, from the capabilities:
{"id":"psk:JobInputBin","value":"ns0000:Tray3"},
{"id":"psk:PageICMRenderingIntent","value":"psk:Photographs"},
{"id":"psk:PageMediaType","value":"ns0000:Auto"},
{"id":"psk:JobOutputBin","value":"ns0000:Auto"},
//etc.
]
}
}
The first part of the parameters corresponds to the basic settings from the print dialog and they are quite self-explanatory and the values are easy to change. The vendor_ticket_item array is a bit more complicated. It contains id/value pairs described by the printer capabilities we retrieved earlier. The id will contain the name of the parameter from the capabilities and the value will contain the name of one of the records in the parameter options, or a numeric value etc, as described in the capabilities.
That should work just fine for most parameters, but if you get stuck and can't figure out the correct values you can always open a sample document in Chrome and print it. Pick a GCP printer and then click "Print using Google Cloud Print dialog..." and from the "Advanced options" make the exact settings that you need. Using something like Fiddler extract the value of the ticket parameter from POST request Chrome does to the /cloudprint/submit service.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With