Google Slides: Page, Export as PNG
Google Slides: Page, Export as PNG
Stores a PNG image file as Workflow data with converting the specified slide. Or gets the download URL to the PNG image which has a lifetime of 30 minutes. For example, it is used in the business process of the Sales Report by email with PNG image.
Configs
  • U: Select HTTP_Authz Setting *
  • A: Set FILE-ID in Drive *#{EL}
  • B: Set Object-ID of Slide Page (Chars following “id.”)#{EL}
  • C1: Select FILES DATA for PNG Image (append) *
  • C2: Set FILE NAME if you want to store with a different name#{EL}
  • D: Select STRING DATA for URL to download (update)
Script (click to open)
// GraalJS Script (engine type: 2)

//////// START "main()" /////////////////////////////////////////////////////////////////

main();
function main(){ 

//// == Config Retrieving / 工程コンフィグの参照 ==
const strAuthzSetting     = configs.get      ( "AuthzConfU" );   /// REQUIRED
  engine.log( " AutomatedTask Config: Authz Setting: " + strAuthzSetting );
const strInputfileId      = configs.get      ( "StrConfA1" );    /// REQUIRED
  if( strInputfileId    === "" ){
    throw new Error( "\n AutomatedTask ConfigError:" +
                     " Config {A1: FileID} is empty \n" );
  }
let   strPageidOriginal   = configs.get      ( "StrConfB1" );    // NotRequired
const filesPocketImg      = configs.getObject( "SelectConfC1" ); /// REQUIRED
let   strSaveas           = configs.get      ( "StrConfC2" );    // NotRequired
const strPocketUrl        = configs.getObject( "SelectConfD" );  // NotRequired


//// == Data Retrieving / ワークフローデータの参照 ==
let filesAttached = engine.findData( filesPocketImg ); // java.util.ArrayList
if( filesAttached === null ) {
  engine.log( " AutomatedTask FilesArray {C1} (empty)" );
  filesAttached = new java.util.ArrayList();
}else{
  engine.log( " AutomatedTask FilesArray {C1}: " +
              filesAttached.size() + " files" );
}


//// == Calculating / 演算 ==

/// Get FileTitle (and LastPageID)
/// Google Slides API
/// https://developers.google.com/slides/reference/rest/v1/presentations/get
// request0, prepare
let request0Uri = "https://slides.googleapis.com/v1/presentations/" + strInputfileId;
let request0    = httpClient.begin(); // HttpRequestWrapper
    request0    = request0.authSetting( strAuthzSetting ); // with "Authorization: Bearer XX"
    // https://questetra.zendesk.com/hc/en-us/articles/360024574471-R2300#HttpRequestWrapper
// request0, try
const response0 = request0.get( request0Uri ); // HttpResponseWrapper
engine.log( " AutomatedTask ApiRequest0 Start: " + request0Uri );
const response0Code = response0.getStatusCode() + "";
const response0Body = response0.getResponseAsString() + "";
engine.log( " AutomatedTask ApiResponse Status: " + response0Code );
if( response0Code !== "200"){
  throw new Error( "\n AutomatedTask UnexpectedResponseError: " +
                    response0Code + "\n" + response0Body + "\n" );
}
// response0, parse
/* 
engine.log( response1Body ); // debug
{
  "presentationId": "1MsdTWR_pN4FQTCCqUhC1F_JWWsagogISvPF9WqOmaq8",
  "pageSize": { ## },
  "slides": [
    {
      "objectId": "p",
      "pageElements": [ ## ],
      "slideProperties": { ## },
      "pageProperties": { ## }
    },
    {
      "objectId": "g6251321494_0_0",
      "pageElements": [ ## ],
      "slideProperties": { ## },
      "pageProperties": { ## }
    },
    {
      "objectId": "SLIDES_API66619114_0",
      "pageElements": [ ## ],
      "slideProperties": { ## },
      "pageProperties": { ## }
    }
  ],
  "title": "Revenue Report Example",
  "masters": [ ## ],
  "layouts": [ ## ],
  "locale": "ja",
  "revisionId": "bvHyj2SJ0wwg4A",
  "notesMaster": { ## }
}
*/
const response0Obj = JSON.parse( response0Body );
engine.log( " AutomatedTask ApiResponse File Title: " + response0Obj.title );
if( strPageidOriginal === "" ){
  strPageidOriginal = response0Obj.slides[ response0Obj.slides.length - 1 ].objectId;
}
if( strSaveas === "" ){
  strSaveas = response0Obj.title + ".png";
}

/// Generates a thumbnail (PNG image)
/// Google Slides API
/// https://developers.google.com/slides/reference/rest/v1/presentations.pages/getThumbnail
let request1Uri = "https://slides.googleapis.com/v1/presentations/" +
                  strInputfileId + "/pages/" + strPageidOriginal + "/thumbnail";
let request1    = httpClient.begin(); // HttpRequestWrapper
    request1    = request1.authSetting( strAuthzSetting ); // with "Authorization: Bearer XX"
    // https://questetra.zendesk.com/hc/en-us/articles/360024574471-R2300#HttpRequestWrapper
// request1, try
const response1     = request1.get( request1Uri ); // HttpResponseWrapper
engine.log( " AutomatedTask ApiRequest1 Start: " + request1Uri );
const response1Code = response1.getStatusCode() + "";
const response1Body = response1.getResponseAsString() + "";
engine.log( " AutomatedTask ApiResponse Status: " + response1Code );
if( response1Code !== "200"){
  throw new Error( "\n AutomatedTask UnexpectedResponseError: " +
                    response1Code + "\n" + response1Body + "\n" );
}
// response1, parse
/* 
engine.log( response1Body ); // debug
{
  "width": 1600,
  "height": 900,
  "contentUrl": "https://lh3.googleusercontent.com/fz##230##Cg=s1600"
}
*/
const response1Obj = JSON.parse( response1Body );
engine.log( " AutomatedTask ApiResponse: width "  + response1Obj.width );
engine.log( " AutomatedTask ApiResponse: height " + response1Obj.height );

/// Get PNG via "contentUrl"
// request2, prepare
let request2Uri = response1Obj.contentUrl;
let request2    = httpClient.begin(); // HttpRequestWrapper
// request2, try
const response2     = request2.get( request2Uri ); // HttpResponseWrapper
engine.log( " AutomatedTask ApiRequest2 Start: " + request2Uri );
const response2Code = response2.getStatusCode() + "";
engine.log( " AutomatedTask ApiResponse Status: " + response2Code );
if( response2Code !== "200"){
  throw new Error( "\n AutomatedTask UnexpectedResponseError: " +
                    response2Code + "\n" + response2.getResponseAsString() + "\n" );
}
const qfile = new com.questetra.bpms.core.event.scripttask.NewQfile(
    strSaveas, response2.getContentType(), response2.getResponse()
  );
filesAttached.add( qfile );


//// == Data Updating / ワークフローデータへの代入 ==
engine.setData( filesPocketImg,  filesAttached );
if( strPocketUrl !== null ){
  engine.setData( strPocketUrl,  request2Uri );
}


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


/*
Notes:
- The entire image of the specified page is converted to PNG and saved. GoogleSlidesExport
    - If no page is specified, the last page will be converted to PNG.
- The download URL to the image is tagged with the account of the requester.
    - Anyone with the URL effectively accesses the image as the original requester.
    - Access to the image may be lost if the presentation's sharing settings change. 
    - If need to specify the size, replace =s1600 at the end of the URL with =s1200. (As of 2021-05)
- For example, if you want to automate the notification of "Monthly Sales Report", define as follows:
    - The template page is automatically duplicated (Google Slides: Page, Duplicate)
    - The report text part is automatically replaced (Google Slides: Page, Replace Strings)
    - The embedded graph is automatically updated (Google Slides: Page, Refresh Charts)
    - The slide page is automatically converted to a PNG image (Google Slides: Page, Generate PNG)
    - The email with the PNG image attached will be sent automatically. (ThrowEmail Event)

Notes-ja:
- 指定ページのページ全体をPNG化して保存します。 GoogleSlidesExport
    - もしページ指定がない場合は、最終ページをPNG化します。
- ダウンロード用URL(30分間のみ有効)はAPI通信の認可者に紐づけられます。
    - URLを知っている人は誰でも画像にアクセスできます。そして認可者によるアクセスと見なされます。
    - なお、ファイルの共有設定が変更されるとダウンロード用URLは無効になります。
    - サイズ指定が必要な場合、URL末尾の =s1600 を =s1200 に書き換えるなどして下さい。(2021-05現在)
- たとえば「月次売上レポート」の通知業務を自動化したい場合は、以下のような業務プロセスを定義します。
    - 雛形ページが自動複製され、(※Google スライド: ページ, 複製)
    - 貼り付けられている埋め込みグラフが自動更新され、(※Google スライド: ページ, 文字列全置換)
    - 報告テキスト部が当月文に自動置換され、(※Google スライド: ページ, 全グラフ更新)
    - 当該スライドページがPNG画像に自動変換され、(※Google スライド: ページ, PNG画像生成)
    - PNG画像が添付されたメールが自動的に送信される。(※ ThrowEmail イベント)

APPENDIX-en
- FILE-ID/PresentationID in Drive (Chars following "/d/")
    - docs.google.com/presentation/d/1p33hGJFUNYixBmMeaV81nsOVYGUUrZIFyErinFp3CI8
- Object-ID of Slide Page (Chars following "id.")
    - docs.google.com/presentation/d/1p33hGJFUNYixBmMeaV81nsOVYGUUrZIFyErinFp3CI8/edit#slide=id.g613777c84a_0_0
- Setting example of "HTTP Authentication" (OAuth2)
    - 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/presentations
    - Client ID, Consumer Secret:
        - ( from https://console.developers.google.com/ )
        - Redirect URLs: https://s.questetra.net/oauth2callback
APPENDIX-ja
- FILE-ID/PresentationID in Drive ("/d/" 以降の文字列)
    - docs.google.com/presentation/d/1p33hGJFUNYixBmMeaV81nsOVYGUUrZIFyErinFp3CI8
- Object-ID of Slide Page ("id." 以降の文字列)
    - docs.google.com/presentation/d/1p33hGJFUNYixBmMeaV81nsOVYGUUrZIFyErinFp3CI8/edit#slide=id.g613777c84a_0_0
- "HTTP認証"(OAuth2)の設定例
    - 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/presentations
    - Client ID, Consumer Secret:
        - ( from https://console.developers.google.com/ )
        - Redirect URLs: https://s.questetra.net/oauth2callback
*/

Download

2021-05-18 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/google-slides-page-export-as-png-2021/
The Addon-import feature is available with Professional edition.

Notes

  • The entire image of the specified page is converted to PNG and saved. GoogleSlidesExport
    • If no page is specified, the last page will be converted to PNG.
  • The download URL to the image is tagged with the account of the requester.
    • Anyone with the URL effectively accesses the image as the original requester.
    • Access to the image may be lost if the presentation’s sharing settings change.
    • If need to specify the size, replace =s1600 at the end of the URL with =s1200. (As of 2021-05)
  • For example, if you want to automate the notification of “Monthly Sales Report”, define as follows:
    • The template page is automatically duplicated (Google Slides: Page, Duplicate)
    • The report text part is automatically replaced (Google Slides: Page, Replace Strings)
    • The embedded graph is automatically updated (Google Slides: Page, Refresh Charts)
    • The slide page is automatically converted to a PNG image (Google Slides: Page, Generate PNG)
    • The email with the PNG image attached will be sent automatically. (ThrowEmail Event)

Capture

Stores a PNG image file as Workflow data with converting the specified slide. Or gets the download URL to the PNG image which has a lifetime of 30 minutes. For example, it is used in the business process of the Sales Report by email with PNG image.
Stores a PNG image file as Workflow data with converting the specified slide. Or gets the download URL to the PNG image which has a lifetime of 30 minutes. For example, it is used in the business process of the Sales Report by email with PNG image.

Appendix

See also

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: