我正在尝试创建自动系统,该系统将在表单提交时打印。 到目前为止,脚本从表单提交开始,并将所需信息放入单独的工作表中的打印模板,我想将此工作表发送到云打印机。 在这里OAuth2 with Google Cloud Print我找到了如何将作业从脚本发送到云打印机,但我遇到了两个问题:
以下是打印功能的代码:
function printGoogleDocument(docId) {
// For notes on ticket options see https://developers.google.com/cloud-print/docs/cdd?hl=en
var ticket = {
version: "1.0",
print: {
color: {
type: "STANDARD_COLOR"
},
duplex: {
type: "NO_DUPLEX"
},
media_size: {
option: [
{
"name": "ISO_A6",
"width_microns": 105000,
"height_microns": 148000
}
]
},
}
};
var payload = {
"printerid" : "_my_printer_ID",
"content" : docId,
"title" : "Test",
"contentType" : "google.spreadsheet", // allows you to print google docs
"ticket" : JSON.stringify(ticket),
};
var response = UrlFetchApp.fetch('https://www.google.com/cloudprint/submit', {
method: "POST",
payload: payload,
headers: {
Authorization: 'Bearer ' + getCloudPrintService().getAccessToken()
},
"muteHttpExceptions": true
});
// If successful, should show a job here: https://www.google.com/cloudprint/#jobs
response = JSON.parse(response);
if (response.success) {
Logger.log("%s", response.message);
} else {
Logger.log("Error Code: %s %s", response.errorCode, response.message);
}
return response;
}