I need to send print Job to my printer using Google Cloud Print. It is a Classic Printer Named RISO ComColor 7150. My Code in Apps Script is as follows:-
function printGoogleDocument(docID, printerID, docName , type , duplex) {
var ticket = {
version: "1.0",
print: {
color: {
type: type,
vendor_id: "Color"
},
duplex: {
type: duplex
}
}
};
var payload = {
"printerid" : printerID,
"title" : docName,
"content" : DriveApp.getFileById(docID).getBlob(),
"contentType": "application/pdf",
"ticket" : JSON.stringify(ticket),
"pages" : "1,2"
};
var response = UrlFetchApp.fetch('https://www.google.com/cloudprint/submit', {
method: "POST",
payload: payload,
headers: {
Authorization: 'Bearer ' + getCloudPrintService().getAccessToken()
},
"muteHttpExceptions": true
});
response = JSON.parse(response);
if (response.success) {
Logger.log("%s", response.message);
} else {
Logger.log("Error Code: %s %s", response.errorCode, response.message);
}
}
problem is When i am Sending type to STANDARD_COLOR and duplex to NO_DUPLEX than it is Working fine but when i change them to MONOCHROME and DUPLEX than it is Giving me Color print with no duplex again. Also i am Sending Page Number but it Prints whole pdf instead of giving me print of specific page.
Can Anybody tell me what i am doing worng here??
Thanks in Advance.
you can set all the things in print job ticket, no need to specify the page number outside ticket. Here ,a CJT am recommending ,
var ticket = "{\"version\":\"1.0\",\"print\":{\"color\":{\"vendor_id\":\"1\",\"type\":1},\"duplex\":{\"type\":0},\"page_orientation\":{\"type\":"0"},\"copies\":{\"copies\": "2"},\"fit_to_page\":{\"type\":3},\"page_range\":{\"interval\":[{\"start\": "1",\"end\":"2"}]},\"media_size\":{\"width_microns\":210000,\"height_microns\":297000,\"is_continuous_feed\":false,\"vendor_id\":\"9\"},\"collate\":{\"collate\":false},\"reverse_order\":{\"reverse_order\":false}}}";
so you can specify duplex, page limit..etc
It would be nice if you can go this documentation.
https://developers.google.com/cloud-print/docs/cdd#pts
And for duplex,its an integer expecting, you can set this way..if NO_DUPLEX is needed you need to send 0, NO_DUPLEX = 0; LONG_EDGE = 1; SHORT_EDGE = 2;