お知らせ

Google Cloud Print サービスは、2020年12月31日に終了しましたhttps://www.google.com/intl/ja_ALL/cloudprint/learn/
Google Cloud Print ジョブ送信 (Single)

ワークフローデータとして添付されているファイル群を印刷します。(Google Cloud Print 経由)

2016-11-07 © Questetra, Inc. (MIT License)
https://support.questetra.com/ja/addons/googlecloudprint-print/

Configs
  • A: OAuth2通信許可設定名 (←[OAuth 2.0 設定]) *
  • B: Printer ID を入力してください *
  • C: Printファイルが格納されているファイル型データを選択してください *
  • D: Cloud Job Ticket が格納されている文字列型データor選択肢型データを選択してください
  • X: 通信ログが格納される文字列型データを選択してください (更新)
Script
// OAuth2 Example Setting:
// <Google Developers Console>
// Application Type: Web Application
// Name: questetra-print
// Redirect URL: https://s.questetra.net/oauth2callback
// <Questetra OAuth2.0 Setting of Workflow App>
// Name: google-cloud-print
// Authorization Endpoint URL: https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force
// Token Endpoint URL: https://accounts.google.com/o/oauth2/token
// Scope: https://www.googleapis.com/auth/cloudprint
// Consumer Key: (Copy from Google Developers Console)
// Consumer Secret: (Copy from Google Developers Console)
/// https://console.developers.google.com/apis/credentials

// PrinterID: Get via "chrome://devices/"
// Cloud Job Ticket (CJT):
// REF https://developers.google.com/cloud-print/docs/cdd#cjt
// If not specified, it is printed with the printer's default setting '{"version": "1.0", "print": {}}'
// Other Examples
// {"version":"1.0","print":{"vendor_ticket_item":[],"duplex":{"type":"LONG_EDGE"}}}
// {"version":"1.0","print":{"vendor_ticket_item":[],"color":{"type":"STANDARD_MONOCHROME"},"copies":{"copies": 2}}}

// Supported File Types:
// "text/html", "text/plain", "application/postscript",,,
// "application/pdf", "image/jpeg", "image/png",,,
// "application/vnd.openxmlformats-officedocument.wordprocessingml.document" (docx),,,
// "application/vnd.openxmlformats-officedocument.presentationml.presentation" (pptx),,,
// REF https://developers.google.com/cloud-print/docs/appDevGuide
// REF https://developers.google.com/cloud-print/docs/appInterfaces



//////// START "main()" ////////
main();
function main(){ 

//// == Config Retrieving / 工程コンフィグの参照 ==
const dataIdC = configs.get( "conf_DataIdC" ) + "";
// 'java.lang.String' (String Obj) to javascript primitive 'string'
// https://wiki.openjdk.java.net/display/Nashorn/Rhino+Migration+Guide#RhinoMigrationGuide-JavaScriptvsJavaStrings
// https://docs.oracle.com/javase/8/docs/technotes/guides/scripting/nashorn/api.html#sthref21

const oauth2    = configs.get( "conf_OAuth2" ) + "";
const printerId = configs.get( "conf_PrinterId" ) + "";
let   jobTicket = configs.get( "conf_JobTicket" ) + "";
  if( jobTicket === "" ){
    jobTicket = '{"version": "1.0", "print": {}}';
  }


//// == Data Retrieving / ワークフローデータの参照 ==
const myFiles   = engine.findDataByNumber( dataIdC ); // java.util.ArrayList
// com.questetra.bpms.core.event.scripttask.NewQfile
if( myFiles === null ){
  throw new Error( "Files data is NULL" );
}

//// == Calculating / 演算 ==
const jobTitle  = "Questetra-" + processInstance.getProcessInstanceId() + "";
const token     = httpClient.getOAuth2Token( oauth2 );

for( let i = 0; i < myFiles.size(); i++ ){
  // prepare API Request
  // com.questetra.bpms.core.event.scripttask.HttpClientWrapper
  let apiRequest = httpClient.begin(); // HttpRequestWrapper
  apiRequest     = apiRequest.bearer( token );
  apiRequest     = apiRequest.multipart( "title", jobTitle );
  apiRequest     = apiRequest.multipart( "printerid", printerId );
  apiRequest     = apiRequest.multipart( "ticket", jobTicket );
  apiRequest     = apiRequest.multipart( "content", myFiles.get(i) );

  // access API (with post())
  let response   = apiRequest.post( "https://www.google.com/cloudprint/submit" );
  let httpStatus = response.getStatusCode() + "";
  let responseStr= response.getResponseAsString() + "";
  engine.log( "Submit Print Job: " + jobTitle + " (" + httpStatus + ")" );
  if( httpStatus !== "200" ){
    let errorMessage = "\n- HTTP STATUS is not 200, Service Task stopped. -\n";
    errorMessage += responseStr + "\n";
    throw new Error( errorMessage );
  }
}


//// == Data Updating / ワークフローデータへの代入 ==
// (nothing)

} //////// END "main()" ////////

Download

Capture

注意事項

  • ファイル型データ項目内に添付されている全てのファイルが印刷されます
  • PDF Docx など、様々なファイルデータが印刷可能です
  • 印刷ジョブの受信までに、数秒から30秒程度のタイムラグが発生する場合があります
  • あらかじめ「chrome://devices/」にて、プリンタを追加し、プリンタID(B)を取得しておく必要があります
    • 「クラウド対応プリンタ」は他の誰かのアカウントで登録されていると『chrome://devices/』の「新しいデバイス」に表示されない場合があります
    • 「従来型のプリンタ」(クラウド対応ではないプリンタ)は、ホストPCの電源が投入された際に印刷されます
  • あらかじめ「Google Developers Console」にて OAuth2 通信の「クライアントID」および「クライアントシークレット」を取得しておく必要があります
  • ワークフローアプリの編集画面で OAuth2 通信を登録し、認可(許可)しておく必要があります
  • 印刷オプションは「Cloud Job Ticket 書式」(CJT)にて設定します 参照
    • 無指定の場合、プリンタのデフォルト設定にて印刷されます(CJT= {“version”: “1.0”, “print”: {}} )
    • 両面印刷 = {“version”:”1.0″,”print”:{“vendor_ticket_item”:[],”duplex”:{“type”:”LONG_EDGE”}}}
    • 2部印刷 = {“version”:”1.0″,”print”:{“vendor_ticket_item”:[],”color”:{“type”:”STANDARD_MONOCHROME”},”copies”:{“copies”: 2}}}
  • Config 設定値「プリンタID」や「CJT印刷オプション」は、EL式(例 “#{data[‘1’]}”)をセットすることにより、ワークフローデータを参照させることも可能です
%d人のブロガーが「いいね」をつけました。