Google Cloud Print的打印机设置 [英] Printer settings with Google Cloud Print

查看:511
本文介绍了Google Cloud Print的打印机设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何想从浏览器进行无人值守打印的人都知道这不是一件容易的事,另一方面,这对于任何后台应用程序都是非常有用的.然后,谷歌开始使用GCP拯救我们.

因此我进行了设置,并在几分钟后打印了文档.但是后来我想对打印机应用一些设置.这是您意识到该文档完全缺乏的那一刻.甚至没有解释如何将页面设置为横向这样简单的事情.

文档仅表示您必须发送功能参数.即使能够检索打印机的功能,您也会意识到,顾名思义,它描述的是所有打印机功能,而不是特定打印作业的设置.

那么您实际上如何指定打印作业设置?

解决方案

首先,GCP文档错误地指出您可以使用/list服务界面来检索打印机功能.那不行您必须调用/printer服务,该服务确实会返回打印机功能.这些功能只是一个JSON列表,每个JSON描述一个打印机参数以及该参数可以采用的可能值.有时它也可以包含一些其他信息.例如,以下是我的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"
  }
  ]

通过查看Chrome从GCP对话框发送的POST请求,我发现/submit服务根本不使用功能参数.实际上,它使用名为 ticket 的参数来指定打印作业设置.参数的格式非常简单,它是一个如下所示的JSON:

{
"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.
    ]
  }
}

参数的第一部分与打印对话框中的基本设置相对应,它们很容易解释,并且值很容易更改. vendor_ticket_item 数组要复杂一些.它包含ID/值对,这些ID/值对由我们之前检索的打印机功能描述. id 将包含功能中参数的 name ,而 value 将包含以下项之一的 name 功能中所述的参数选项中的记录或数值等.

这对于大多数参数来说应该可以正常工作,但是如果您卡住并且无法确定正确的值,则可以始终在Chrome中打开示例文档并进行打印.选择一台GCP打印机,然后单击使用Google Cloud Print对话框打印...",然后从高级选项"中进行所需的确切设置.使用类似 Fiddler 之类的东西,从POST请求中提取票证参数的值,Chrome会将其发送到/cloudprint/submit服务.

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?

解决方案

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.

这篇关于Google Cloud Print的打印机设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆