Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Copyright Google LLC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- // [START apps_script_slides_speaker_notes_script]
- var DOCUMENT_ID = "1lWaYc0D6VaR9C2AB5UmNOeM0nBBXZqVox9LJOzoexKM"
- /**
- * Runs when the add-on is installed.
- * @param {object} e The event parameter for a simple onInstall trigger. To
- * determine which authorization mode (ScriptApp.AuthMode) the trigger is
- * running in, inspect e.authMode. (In practice, onInstall triggers always
- * run in AuthMode.FULL, but onOpen triggers may be AuthMode.LIMITED or
- * AuthMode.NONE.)
- */
- function onInstall(e) {
- onOpen();
- }
- /**
- * Trigger for opening a presentation.
- * @param {object} e The onOpen event.
- */
- function onOpen(e) {
- SlidesApp.getUi().createAddonMenu()
- .addItem('Generate Script Document', 'generateSlidesScript')
- .addToUi();
- }
- /**
- * Creates a 'script' for the presentation user in a document
- * with the speaker notes for each slide.
- */
- function generateSlidesScript() {
- var presentation = SlidesApp.getActivePresentation();
- //var docTitle = presentation.getName() + ' Script';
- //var slides = presentation.getSlides();
- // Get Thumnnails
- var baseUrl =
- "https://slides.googleapis.com/v1/presentations/{presentationId}/pages/{pageObjectId}/thumbnail?thumbnailProperties.thumbnailSize=MEDIUM"
- /*+ "thumbnailProperties.mimeType=PNG"
- + "&thumbnailProperties.thumbnailSize=SMALL"
- + "&key=AIzaSyAK5DAuBCBjwunZ_Dbv4rKK1h9wkQmiAFU"*/;
- var parameters = {
- method: "GET",
- headers: { Authorization: "Bearer " + ScriptApp.getOAuthToken() },
- contentType: "application/json",
- muteHttpExceptions: true
- };
- // Creates a document in the user's home Drive directory.
- //var speakerNotesDoc = DocumentApp.create(docTitle);
- //console.log('Created document with id %s', speakerNotesDoc.getId());
- //var docBody = speakerNotesDoc.getBody();
- //var header = docBody.appendParagraph(docTitle);
- //header.setHeading(DocumentApp.ParagraphHeading.HEADING1);
- // For storing all of our data
- var rows = [];
- console.log('Starting Loop');
- var slides = presentation.getSlides().forEach(function(slide, index) {
- console.log('Slide ' + (index + 1));
- var url = baseUrl
- .replace("{presentationId}", presentation.getId())
- .replace("{pageObjectId}", slide.getObjectId());
- console.log('URL ' + url);
- var response = JSON.parse(UrlFetchApp.fetch(url, parameters));
- console.log('Response Content URL ' + response.contentUrl);
- var notes = slide.getNotesPage().getSpeakerNotesShape().getText().asString();
- console.log('Notes: ' + notes);
- rows.push([index, notes, response.contentUrl]);
- });
- addTableInDocument(rows);
- console.log('https://docs.google.com/document/d/' + DOCUMENT_ID);
- }
- function addTableInDocument(rows) {
- var doc = DocumentApp.openById(DOCUMENT_ID);
- // Let's Empty our document
- doc.setText('');
- //get the body section of document
- var body = doc.getBody();
- //Add a table in document
- var table = body.appendTable();
- var rowcounter = 0;
- for (var row of rows){
- var tr = table.appendTableRow();
- for(var column=0; column<3; column++){
- if(column == 2) {
- var imageBlob = UrlFetchApp.fetch(row[column]).getBlob();
- var imageBlobSize = ImgApp.getSize(imageBlob);
- var imageBlobAspectRation = imageBlobSize.width / imageBlobSize.height;
- var td = tr.appendTableCell().insertImage(0, imageBlob).setWidth(320).setHeight(180);
- } else {
- var td = tr.appendTableCell(row[column]);
- }
- }
- rowcounter++;
- }
- //Save and close the document
- doc.saveAndClose();
- }
- // [END apps_script_slides_speaker_notes_script]
- {
- "timeZone": "Australia/Sydney",
- "dependencies": {
- "enabledAdvancedServices": [{
- "userSymbol": "Docs",
- "serviceId": "docs",
- "version": "v1"
- }, {
- "userSymbol": "Drive",
- "serviceId": "drive",
- "version": "v2"
- }, {
- "userSymbol": "Slides",
- "serviceId": "slides",
- "version": "v1"
- }],
- "libraries": [{
- "userSymbol": "ImgApp",
- "libraryId": "1T03nYHRho6XMWYcaumClcWr6ble65mAT8OLJqRFJ5lukPVogAN2NDl-y",
- "version": "5"
- }]
- },
- "exceptionLogging": "STACKDRIVER",
- "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"],
- "runtimeVersion": "DEPRECATED_ES5"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement