Insert From Drawings

November 10, 2017Data Automations, Portfoliogoogle apps script, google drawings, google slides, community suggestions, features

During the #GoogleEI twitter chat, an idea was proposed and I couldn’t help but give it a try.

Thanks to @jentechnology for the great idea. Check her out on Twitter to see the super cool stuff she is doing with using slides to create yearbooks.

I had no idea, but you can’t actually import a drawing directly into a slide. You can only import image files. Well with, a little bit of code I fixed that.

I used the basic file-select documentation to build the file picker itself. This is pretty easy to follow along with here.

Once you have done that, a little bit of manipulation and you are golden.

function getDrawing(drawingId) {
  var image = Drive.Files.get(drawingId);

  var imageBlob = getBlob(image.exportLinks['image/jpeg']);
  var presentation = SlidesApp.getActivePresentation();
  var currentPage = presentation.getSelection().getCurrentPage();
  currentPage.insertImage(imageBlob);
}

function getBlob(url) {
  var response = UrlFetchApp.fetch(url, {
    headers: {
      Authorization: 'Bearer ' + ScriptApp.getOAuthToken(),
    },
  });

  return response.getBlob();
}

I did publish it to the add-on store, but it is unlisted. Installing add-ons is the easy way out! Look at the code, use the code, and improve the code!

Github Repository

Chrome Web Store

jordan rhea

Jordan Rhea - I’m a front-end web developer. Follow me at @rheajt if you want to talk, discuss, or fix any of my code! I am passionate about using JavaScript in Google projects, but there are many more applications. I want to learn them all.