2

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.

1
  • are you using ajax at all in the page view? if so you need to do some "fun stuff" Commented Mar 9, 2016 at 6:15

1 Answer 1

4

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;

Sign up to request clarification or add additional context in comments.

3 Comments

it is giving me error when i used this. Saying Error Code: 424.0 Failed to parse the print job's print ticket. @AhammadaliPK
Thank you Very Much....This Made My work.....i should have read that one day earlier.....
Happy to hear .carry on

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.