kandi background
Explore Kits

GoogleCloudPrint | Google Cloud Print API for Java | GCP library

 by   jittagornp Java Version: Current License: Apache-2.0

 by   jittagornp Java Version: Current License: Apache-2.0

Download this library from

kandi X-RAY | GoogleCloudPrint Summary

GoogleCloudPrint is a Java library typically used in Cloud, GCP applications. GoogleCloudPrint has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has low support. You can download it from GitHub.
There are two ways to do that:. Recommended from João Vianey (Google Cloud Print developer) Thank you very much.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • GoogleCloudPrint has a low active ecosystem.
  • It has 47 star(s) with 28 fork(s). There are 10 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 2 open issues and 1 have been closed. On average issues are closed in 3 days. There are 1 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of GoogleCloudPrint is current.
GoogleCloudPrint Support
Best in #GCP
Average in #GCP
GoogleCloudPrint Support
Best in #GCP
Average in #GCP

quality kandi Quality

  • GoogleCloudPrint has 0 bugs and 0 code smells.
GoogleCloudPrint Quality
Best in #GCP
Average in #GCP
GoogleCloudPrint Quality
Best in #GCP
Average in #GCP

securitySecurity

  • GoogleCloudPrint has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • GoogleCloudPrint code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
GoogleCloudPrint Security
Best in #GCP
Average in #GCP
GoogleCloudPrint Security
Best in #GCP
Average in #GCP

license License

  • GoogleCloudPrint is licensed under the Apache-2.0 License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
GoogleCloudPrint License
Best in #GCP
Average in #GCP
GoogleCloudPrint License
Best in #GCP
Average in #GCP

buildReuse

  • GoogleCloudPrint releases are not available. You will need to build from source code and install.
  • Build file is available. You can build the component from source.
  • Installation instructions are not available. Examples and code snippets are available.
GoogleCloudPrint Reuse
Best in #GCP
Average in #GCP
GoogleCloudPrint Reuse
Best in #GCP
Average in #GCP
Top functions reviewed by kandi - BETA

kandi has reviewed GoogleCloudPrint and discovered the below as its top functions. This is intended to give you an instant insight into GoogleCloudPrint implemented functionality, and help decide if they suit your requirements.

  • Register a printer .
  • Converts an input stream to a string .
  • Login to Google .
  • Main entry point .
  • Returns a String representation of the configuration .
  • Load properties from classpath .
  • Sets the connection status .
  • Sets the output writer capability .
  • Get the horizontal distance .
  • Returns the default value

GoogleCloudPrint Key Features

Load printer capabilities and create an XML(XPS format) file using Windows API. Ex.: Using "PrintQueue" class --> GetPrintCapabilitiesAsXml.WriteTo(file)

Obtaining the PPD file of the PostScript printer. Uploading one of these files, GCP was able to understand the printer capabilities.

Connect to google cloud print

copy iconCopydownload iconDownload
String email = "YOUR_GOOGLE_EMAIL";
String password = "YOUR_GOOGLE_PASSWORD";

GoogleCloudPrint cloudPrint = new GoogleCloudPrint();

//connect to google cloud print
cloudPrint.connect(email, password, "geniustree-cloudprint-1.0");

Disconnect from google cloud print

copy iconCopydownload iconDownload
cloudPrint.disconnect();

Register printer

copy iconCopydownload iconDownload
// create and setup printer

RegisterPrinterResponse response = cloudPrint.registerPrinter(printer);

Job listener

copy iconCopydownload iconDownload
cloudPrint.addJobListener(new JobListener() {
    //
    @Override
    public void onJobArrive(Job job, boolean success, String message) {
    
        //do something ...
    
    }
});    

Submit job

copy iconCopydownload iconDownload
//create and setup job

SubmitJobResponse response = cloudPrint.submitJob(submitJob);

Delete job

copy iconCopydownload iconDownload
//jobId generate by google cloud print

DeleteJobResponse response = cloudPrint.deleteJob(jobId);
LOG.debug("delete job response => {}", response.isSuccess() + ", " + response.getMessage());

Update printer informaton

copy iconCopydownload iconDownload
//printer id = "a1dbe503-eb96-6d26-dc7b-a290a1cfaf3b"

Printer printer = new Printer();
printer.setId("a1dbe503-eb96-6d26-dc7b-a290a1cfaf3b");
printer.setName("Adobe PDF2"); //set new name
printer.setDisplayName("Adobe PDF2");

UpdatePrinterResponse response = cloudPrint.updatePrinter(printer);
LOG.debug("update printer response => {}", response.isSuccess() + ", " + response.getMessage());

Search printer

copy iconCopydownload iconDownload
//search all printers which name is "fax"
//PrinterStatus.ALL is all printer status 
// - ONLINE
// - UNKNOWN
// - OFFLINE
// - DORMANT

SearchPrinterResponse response = cloudPrint.searchPrinter("fax", PrinterStatus.ALL);
if (!response.isSuccess()) {
    LOG.debug("message = > {}", response.getMessage());
    return;
}

for (Printer printer : response.getPrinters()) {
    LOG.debug("printer => {}", printer);
}

Get printer information

copy iconCopydownload iconDownload
//printer id = "dc6929f5-8fdc-5228-1e73-c9dee3298445"

PrinterInformationResponse response = cloudPrint.getPrinterInformation("dc6929f5-8fdc-5228-1e73-c9dee3298445");
if (!response.isSuccess()) {
    LOG.debug("message = > {}", response.getMessage());
    return;
}

for (Printer printer : response.getPrinters()) {
    LOG.debug("printer information response => {}", printer);
}

Update job status (Control job)

copy iconCopydownload iconDownload
//parameter
//job id : get from subscribe job (generate by google cloud print)
//job status : 
// - QUEUED
// - IN_PROGRESS
// - DONE
// - ERROR
//job code : get from printer
//job message : get from printer

ControlJobResponse response = cloudPrint.controlJob(job.getId(), JobStatus.IN_PROGRESS, 100, "PROGRESSING.");
LOG.debug("control job response=> {}", response.isSuccess() + ", " + response.getMessage());

Get job (print job)

copy iconCopydownload iconDownload
JobResponse response = cloudPrint.getJobs();
if (!response.isSuccess()) {
    LOG.debug("message = > {}", response.getMessage());
    return;
}

for (Job job : response.getJobs()) {
    LOG.debug("job response => {}", job);
}

Delete printer

copy iconCopydownload iconDownload
//printer id = "12280cbe-6486-2c98-c65a-22083bd18b5b"

DeletePrinterResponse response = cloudPrint.deletePrinter("12280cbe-6486-2c98-c65a-22083bd18b5b");
LOG.debug("delete printer response => {}", response.isSuccess() + ", " + response.getMessage());

Share printer

copy iconCopydownload iconDownload
//printer id = "dc6929f5-8fdc-5228-1e73-c9dee3298445"
//target email = "jittagorn@geniustree.co.th"

SharePrinterResponse response = cloudPrint.sharePrinter("dc6929f5-8fdc-5228-1e73-c9dee3298445", "jittagorn@geniustree.co.th");
LOG.debug("share printer message => {}", response.isSuccess() + ", " + response.getMessage());

Run Google script on single sheet instead of entire spreadsheet

copy iconCopydownload iconDownload
function onFormSubmit(e){
  // Initialize
  var rng = e.range;
  var sheet = rng.getSheet();
  var name = sheet.getName();

  // If the response was not submitted to the right sheet, exit.
  if(name != "Responses 1") return; 

  //Otherwise continue
}
-----------------------
function onFormSubmit(e) {
  // Initialize
  var name = e.range.getSheet().getName();
  // If the response was not submitted to the right sheet, exit.
  if (name != "Job Submission") return;
  var values = e.values;
  var returnedDocValues = createNewDoc(values);
  var copyId = returnedDocValues[0];
  var docName = returnedDocValues[1];
  printGoogleDocument(copyId, docName);
}

Function not executing with defined variables

copy iconCopydownload iconDownload
//Starting at the code here
// Move file to folder
var file = DriveApp.getFileById(copyId);
DriveApp.getFolderById("").addFile(file);
file.getParents().next().removeFile(file);

//Add this
var newDocName = docName + ' for ' + job_name;
return [file, newDocName];
//To this point
// When Form Gets submitted
function onFormSubmit(e) {
  var values = e.values;
  var returnedDocValues = createNewDoc(values);
  var file = returnedDocValues[0];
  var docName= returnedDocValues[1];
  printGoogleDocument(file, docName);
}
-----------------------
//Starting at the code here
// Move file to folder
var file = DriveApp.getFileById(copyId);
DriveApp.getFolderById("").addFile(file);
file.getParents().next().removeFile(file);

//Add this
var newDocName = docName + ' for ' + job_name;
return [file, newDocName];
//To this point
// When Form Gets submitted
function onFormSubmit(e) {
  var values = e.values;
  var returnedDocValues = createNewDoc(values);
  var file = returnedDocValues[0];
  var docName= returnedDocValues[1];
  printGoogleDocument(file, docName);
}

Merging two functions and executing in sequence

copy iconCopydownload iconDownload
var addFive = function(number, callback){

 number += 5;

  if (callback) {

    return callback(number);

  }

  return number;


}

var multiplyByFive = function(number, callback){

 number *= 5;

  if (callback) {

    return callback(number);

  }

  return number;


}

var subtractFive = function(number, callback){

number -= 5;

  if (callback) {

    return callback(number);
  }

  return number;

}
function test() {

  var result =  addFive(7, function(number) {

   return multiplyByFive(number, function(number){

     return subtractFive(number);

    });

  });

  Logger.log(result); //logs (7 + 5) * 5 - 5 = 55


}
-----------------------
var addFive = function(number, callback){

 number += 5;

  if (callback) {

    return callback(number);

  }

  return number;


}

var multiplyByFive = function(number, callback){

 number *= 5;

  if (callback) {

    return callback(number);

  }

  return number;


}

var subtractFive = function(number, callback){

number -= 5;

  if (callback) {

    return callback(number);
  }

  return number;

}
function test() {

  var result =  addFive(7, function(number) {

   return multiplyByFive(number, function(number){

     return subtractFive(number);

    });

  });

  Logger.log(result); //logs (7 + 5) * 5 - 5 = 55


}
-----------------------
// Work Order


// Get template from Google Docs and name it
var docTemplate = ""; // *** replace with your template ID ***
var docName = "Work Order";

function addDates() {
  var date = new Date(); // your form date
  var holiday = ["09/04/2017", "10/09/2017", "11/23/2017", "12/24/2017", "12/25/2017", "01/01/2018"]; //Define holiday dates in MM/dd/yyyy
  var days = 5; //No of days you want to add
  date.setDate(date.getDate());
  var counter = 0;
  if (days > 0) {
    while (counter < days) {
      date.setDate(date.getDate() + 1);
      var check = date.getDay();
      var holidayCheck = holiday.indexOf(Utilities.formatDate(date, "EDT", "MM/dd/yyyy"));
      if (check != 0 && check != 6 && holidayCheck == -1) {
        counter++;
      }
    }
  }
  Logger.log(date) //for this example will give 08/16/2017
  return date;
}

function createNewDoc(values) {
//Get information from form and set as variables
  var email_address = "";
  var job_name = values[1];
  var ship_to = values[11];
  var address = values[12];
  var order_count = values[7];
  var program = values[2];
  var workspace = values[3];
  var offer = values[4];
  var sort_1 = values[5];
  var sort_2 = values[6];
  var image_services = values[9];
  var print_services = values[10];
  var priority = values[13];
  var notes = values[14];
  var formattedDate = Utilities.formatDate(new Date(), "EDT", "MM/dd/yyyy");
  var expirationDate = Utilities.formatDate(addDates(), "EDT", "MM/dd/yyyy");

  // Get document template, copy it as a new temp doc, and save the Doc's id
  var copyId = DriveApp.getFileById(docTemplate)
    .makeCopy(docName + ' for ' + job_name)
    .getId();
  // Open the temporary document
  var copyDoc = DocumentApp.openById(copyId);
  // Get the document's body section
  var copyBody = copyDoc.getActiveSection();

  // Replace place holder keys,in our google doc template  
  copyBody.replaceText('keyJobName', job_name);
  copyBody.replaceText('keyShipTo', ship_to);
  copyBody.replaceText('keyAddress', address);
  copyBody.replaceText('keyOrderCount', order_count);
  copyBody.replaceText('keyProgram', program);
  copyBody.replaceText('keyWorkspace', workspace);
  copyBody.replaceText('keyOffer', offer);
  copyBody.replaceText('keySort1', sort_1);
  copyBody.replaceText('keySort2', sort_2);
  copyBody.replaceText('keyImageServices', image_services);
  copyBody.replaceText('keyPrintServices', print_services);
  copyBody.replaceText('keyPriority', priority);
  copyBody.replaceText('keyNotes', notes);
  copyBody.replaceText('keyDate', formattedDate);
  copyBody.replaceText('keyDue', expirationDate);

  // Save and close the temporary document
  copyDoc.saveAndClose();

  // Convert temporary document to PDF by using the getAs blob conversion
  var pdf = DriveApp.getFileById(copyId).getAs("application/pdf");

  // Attach PDF and send the email
  var subject = "New Job Submission";
  var body = "Here is the work order for " + job_name + "";
  MailApp.sendEmail(email_address, subject, body, {
    htmlBody: body,
    attachments: pdf
  });

  // Move file to folder
  var file = DriveApp.getFileById(copyId);
  DriveApp.getFolderById("").addFile(file);
  file.getParents().next().removeFile(file);
}

function printGoogleDocument(file, docName) {
  // 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"
      },
    }
  };

  var payload = {
    "printerid": "",
    "content": file,
    "title": docName,
    "contentType": "google.kix", // 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 ' + GoogleCloudPrint.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;
}

// When Form Gets submitted
function onFormSubmit(e) {
  var values = e.values;
  createNewDoc(values);
  printGoogleDocument(file, docName);
}

Community Discussions

Trending Discussions on GoogleCloudPrint
  • Run Google script on single sheet instead of entire spreadsheet
  • Function not executing with defined variables
  • Merging two functions and executing in sequence
Trending Discussions on GoogleCloudPrint

QUESTION

Run Google script on single sheet instead of entire spreadsheet

Asked 2018-Feb-05 at 19:06

With my spreadsheet, I have 2 Google forms tied to 2 sheets. When a form gets submitted the script executes and does it's thing. However, I only want the script to execute based on a submission from a single sheet. As it is now, the script executes when either of the forms get submitted.

My two sheets are: Job Submission and Order Submission

Any advice?

// Work Order


// Get template from Google Docs and name it
var docTemplate = "";  // *** replace with your template ID ***
var docName     = "Work Order";
var printerId   = "";

function addDates() {
    var date = new Date(); // your form date
    var holiday = ["09/04/2017","10/09/2017","11/23/2017","12/24/2017","12/25/2017","01/01/2018"]; //Define holiday dates in MM/dd/yyyy
    var days = 5; //No of days you want to add
    date.setDate(date.getDate());
    var counter = 0;
        if(days > 0 ){
            while (counter < days) {
                date.setDate(date.getDate() + 1 ); 
                var check = date.getDay(); 
                var holidayCheck = holiday.indexOf(Utilities.formatDate(date, "EDT", "MM/dd/yyyy"));
                  if (check != 0 && check != 6  && holidayCheck == -1) {
                         counter++;
                    }
            }
        }
        Logger.log(date) //for this example will give 08/16/2017
    return date;
}

function createNewDoc(values) {
//Get information from form and set as variables
  var email_address = "";
  var job_name = values[1];
  var order_count = values[2];
  var order_form = values[7];
  var print_services = values[3];
  var priority = values[5];
  var notes = values[6];
  var formattedDate = Utilities.formatDate(new Date(), "EDT", "MM/dd/yyyy");
  var expirationDate = Utilities.formatDate(addDates(), "EDT", "MM/dd/yyyy");

// Get document template, copy it as a new temp doc, and save the Doc's id
   var copyId = DriveApp.getFileById(docTemplate)
                .makeCopy(docName+' for '+job_name)
                .getId();
// Open the temporary document
   var copyDoc = DocumentApp.openById(copyId);
// Get the document's body section
   var copyBody = copyDoc.getActiveSection();

// Replace place holder keys,in our google doc template  
   copyBody.replaceText('keyJobName', job_name);
   copyBody.replaceText('keyOrderCount', order_count);
   copyBody.replaceText('keyOrderForm', order_form);
   copyBody.replaceText('keyPrintServices', print_services);
   copyBody.replaceText('keyPriority', priority);
   copyBody.replaceText('keyNotes', notes);
   copyBody.replaceText('keyDate', formattedDate);
   copyBody.replaceText('keyDue', expirationDate);

// Save and close the temporary document
   copyDoc.saveAndClose();

// Convert temporary document to PDF by using the getAs blob conversion
   var pdf = DriveApp.getFileById(copyId).getAs("application/pdf"); 

// Attach PDF and send the email
   var subject = "New Job Submission - " + job_name;
   var body    = "Here is the work order for " + job_name + ". Job is due " + expirationDate + ".";
   MailApp.sendEmail(email_address, subject, body, {htmlBody: body, attachments: pdf}); 

// Move file to folder
   var file = DriveApp.getFileById(copyId);
   DriveApp.getFolderById("").addFile(file);
   file.getParents().next().removeFile(file);

   var newDocName = docName + ' for ' + job_name;
   return [copyId, newDocName];
}

function printGoogleDocument(copyId, docName) {  
  // 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"
      },
    }
  };

  var payload = {
    "printerid" : "",
    "content"   : copyId,
    "title"  : docName,
    "contentType" : "google.kix", // 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 ' + GoogleCloudPrint.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;
}

// When Form Gets submitted
function onFormSubmit(e) { 
  var values = e.values;
  var returnedDocValues = createNewDoc(values);
  var copyId = returnedDocValues[0];
  var docName= returnedDocValues[1];
  printGoogleDocument(copyId, docName);
}

Edit: I'm not sure how to do a complete or verifiable example since it's dependent on the form submission. I don't often work with javascript so I'm still learning.

Anyway, I updated my onFormSubmit function, however, my other functions have failed to execute. The script doesn't create the doc and in turn doesn't get sent to the google cloud print

// When Form Gets submitted
function onFormSubmit(e) { 
// Initialize
  var rng = e.range;
  var sheet = rng.getSheet();
  var name = sheet.getName();
// If the response was not submitted to the right sheet, exit.
  if(name != "Job Submission") return; 
  var values = e.values;
  var returnedDocValues = createNewDoc(values);
  var copyId = returnedDocValues[0];
  var docName= returnedDocValues[1];
  printGoogleDocument(copyId, docName);
}

ANSWER

Answered 2018-Jan-30 at 16:55

If your onFormSubmit function is on a script bounded to the spreadsheet, the event object includes a range object. You could use getSheet to get the sheet and then getName to get the sheet name.

Example:

function onFormSubmit(e){
  // Initialize
  var rng = e.range;
  var sheet = rng.getSheet();
  var name = sheet.getName();

  // If the response was not submitted to the right sheet, exit.
  if(name != "Responses 1") return; 

  //Otherwise continue
}

Source https://stackoverflow.com/questions/48523280

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install GoogleCloudPrint

You can download it from GitHub.
You can use GoogleCloudPrint like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the GoogleCloudPrint component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

Support

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

Explore Related Topics

Share this Page

share link
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.