3

I am trying to create automatic system which will print on form submission. So far script starts on form submission and place desired information into a print template on separate sheet, I want to send this sheet to cloud printer. Over here OAuth2 with Google Cloud Print I have found how to send job from script to cloud printer, but I have 2 problems:

  1. It prints all available sheets, but I need just one;
  2. It prints on Letter/A4 paper, I want it on A6.

Here is the code for print function:

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;
}
Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97

0 Answers0