0

I am currently creating a google doc that provides an overview of all the slides in a presentation using App Scripts. At the moment for each slide I create a thumbnail image and add that to the google doc.

What would be better is an embed of the slide in the doc (so that things such as animations etc show up in the Google doc) - this would be similar to hitting copy on a slide and then paste in Google docs.

Would anyone know how this can be achieved using App Scripts?

For reference this is the function I made for the thumbnails:

// Gets thumbnail URL
function getThumbnail(presentation, slideId) {
  var presentationId = presentation.getId()
  var baseUrl = "https://slides.googleapis.com/v1/presentations/{presentationId}/pages/{pageObjectId}/thumbnail?thumbnailProperties.thumbnailSize=SMALL"
  var url = baseUrl
      .replace("{presentationId}", presentationId)
      .replace("{pageObjectId}", slideId);

  var parameters = {
    method: "GET",
    headers: { Authorization: "Bearer " + ScriptToken },
    contentType: "application/json",
    muteHttpExceptions: true
  };

  var response = JSON.parse(UrlFetchApp.fetch(url, parameters));
  return response.contentUrl
}

// Update Thumbnails in Doc
function updateThumbnailCell(row, contentUrl) {
  var thumbnailCell = row.getCell(THUMBNAIL_DOC_COLUMN)
  thumbnailCell.clear()
  var imageBlob = UrlFetchApp.fetch(contentUrl).getBlob()
  thumbnailCell.insertImage(0, imageBlob).setWidth(200);
}

Cheers,

Shadi

Shadi Almosri
  • 11,678
  • 16
  • 58
  • 80

1 Answers1

1

Appending Google Slides to Document

function slides2Document() {
  var pres = SlidesApp.openById('slides id');
  var doc = DocumentApp.getActiveDocument();
  var body = doc.getBody();
  var slides = pres.getSlides();
  for(var i = 0; i < slides.length; i++) {
    var slide = slides[i];
    var images = slide.getImages();
    for(var j = 0; j < images.length; j++) {
      var img = images[j];
      var imgblob = img.getBlob().getAs('image/gif');
      body.appendImage(imgblob);
    }
  }
}
Shadi Almosri
  • 11,678
  • 16
  • 58
  • 80
Cooper
  • 59,616
  • 6
  • 23
  • 54
  • 1
    Thank you for your answer Cooper. This seems to extract individual images from the slide and then adds them to the document rather than embedding the slide. It causes issue for example if we have multiple images that are then grouped. I see where it's going but ideally we can do a full slide embed rather than taking the individual bits of the slide. I hope that makes sense? – Shadi Almosri Jan 30 '20 at 06:51