Advertisement
Guest User

Script Slide to storyboard

a guest
Dec 12th, 2019
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Copyright Google LLC
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  *     https://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  */
  16.  
  17. // [START apps_script_slides_speaker_notes_script]
  18.  
  19. var DOCUMENT_ID = "1lWaYc0D6VaR9C2AB5UmNOeM0nBBXZqVox9LJOzoexKM"
  20.  
  21. /**
  22.  * Runs when the add-on is installed.
  23.  * @param {object} e The event parameter for a simple onInstall trigger. To
  24.  *     determine which authorization mode (ScriptApp.AuthMode) the trigger is
  25.  *     running in, inspect e.authMode. (In practice, onInstall triggers always
  26.  *     run in AuthMode.FULL, but onOpen triggers may be AuthMode.LIMITED or
  27.  *     AuthMode.NONE.)
  28.  */
  29. function onInstall(e) {
  30.   onOpen();
  31. }
  32.  
  33. /**
  34.  * Trigger for opening a presentation.
  35.  * @param {object} e The onOpen event.
  36.  */
  37. function onOpen(e) {
  38.   SlidesApp.getUi().createAddonMenu()
  39.       .addItem('Generate Script Document', 'generateSlidesScript')
  40.       .addToUi();
  41. }
  42.  
  43. /**
  44.  * Creates a 'script' for the presentation user in a document
  45.  * with the speaker notes for each slide.
  46.  */
  47. function generateSlidesScript() {
  48.   var presentation = SlidesApp.getActivePresentation();
  49.   //var docTitle = presentation.getName() + ' Script';
  50.   //var slides = presentation.getSlides();
  51.  
  52.   // Get Thumnnails
  53.   var baseUrl =
  54.     "https://slides.googleapis.com/v1/presentations/{presentationId}/pages/{pageObjectId}/thumbnail?thumbnailProperties.thumbnailSize=MEDIUM"
  55.   /*+ "thumbnailProperties.mimeType=PNG"
  56.   + "&thumbnailProperties.thumbnailSize=SMALL"
  57.   + "&key=AIzaSyAK5DAuBCBjwunZ_Dbv4rKK1h9wkQmiAFU"*/;
  58.  
  59.   var parameters = {
  60.     method: "GET",
  61.     headers: { Authorization: "Bearer " + ScriptApp.getOAuthToken() },
  62.     contentType: "application/json",
  63.     muteHttpExceptions: true
  64.   };
  65.  
  66.  
  67.   // Creates a document in the user's home Drive directory.
  68.   //var speakerNotesDoc = DocumentApp.create(docTitle);
  69.   //console.log('Created document with id %s', speakerNotesDoc.getId());
  70.  
  71.   //var docBody = speakerNotesDoc.getBody();
  72.   //var header = docBody.appendParagraph(docTitle);
  73.   //header.setHeading(DocumentApp.ParagraphHeading.HEADING1);
  74.  
  75.   // For storing all of our data
  76.   var rows = [];
  77.  
  78.   console.log('Starting Loop');
  79.  
  80.   var slides = presentation.getSlides().forEach(function(slide, index) {
  81.     console.log('Slide ' + (index + 1));
  82.    
  83.     var url = baseUrl
  84.       .replace("{presentationId}", presentation.getId())
  85.       .replace("{pageObjectId}", slide.getObjectId());
  86.     console.log('URL ' + url);
  87.    
  88.     var response = JSON.parse(UrlFetchApp.fetch(url, parameters));
  89.     console.log('Response Content URL ' + response.contentUrl);
  90.    
  91.     var notes = slide.getNotesPage().getSpeakerNotesShape().getText().asString();
  92.     console.log('Notes: ' + notes);
  93.    
  94.     rows.push([index, notes, response.contentUrl]);
  95.    
  96.  
  97.   });
  98.  
  99.   addTableInDocument(rows);
  100.  
  101.   console.log('https://docs.google.com/document/d/' + DOCUMENT_ID);
  102.  }
  103.  
  104. function addTableInDocument(rows) {  
  105.  
  106.   var doc = DocumentApp.openById(DOCUMENT_ID);
  107.  
  108.   // Let's Empty our document
  109.   doc.setText('');
  110.  
  111.   //get the body section of document
  112.   var body = doc.getBody();
  113.  
  114.   //Add a table in document
  115.   var table = body.appendTable();
  116.  
  117.  
  118.   var rowcounter = 0;
  119.   for (var row of rows){
  120.     var tr = table.appendTableRow();
  121.    
  122.     for(var column=0; column<3; column++){
  123.      
  124.       if(column == 2) {
  125.         var imageBlob = UrlFetchApp.fetch(row[column]).getBlob();
  126.         var imageBlobSize = ImgApp.getSize(imageBlob);
  127.         var imageBlobAspectRation = imageBlobSize.width / imageBlobSize.height;
  128.         var td = tr.appendTableCell().insertImage(0, imageBlob).setWidth(320).setHeight(180);
  129.       } else {
  130.         var td = tr.appendTableCell(row[column]);
  131.       }
  132.     }
  133.    
  134.     rowcounter++;    
  135.   }
  136.   //Save and close the document
  137.   doc.saveAndClose();
  138. }
  139.  
  140. // [END apps_script_slides_speaker_notes_script]
  141.  
  142.  
  143. {
  144.   "timeZone": "Australia/Sydney",
  145.   "dependencies": {
  146.     "enabledAdvancedServices": [{
  147.       "userSymbol": "Docs",
  148.       "serviceId": "docs",
  149.       "version": "v1"
  150.     }, {
  151.       "userSymbol": "Drive",
  152.       "serviceId": "drive",
  153.       "version": "v2"
  154.     }, {
  155.       "userSymbol": "Slides",
  156.       "serviceId": "slides",
  157.       "version": "v1"
  158.     }],
  159.     "libraries": [{
  160.       "userSymbol": "ImgApp",
  161.       "libraryId": "1T03nYHRho6XMWYcaumClcWr6ble65mAT8OLJqRFJ5lukPVogAN2NDl-y",
  162.       "version": "5"
  163.     }]
  164.   },
  165.   "exceptionLogging": "STACKDRIVER",
  166.   "oauthScopes": ["https://www.googleapis.com/auth/documents", "https://www.googleapis.com/auth/presentations", "https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/script.external_request"],
  167.   "runtimeVersion": "DEPRECATED_ES5"
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement