Andres
Andres

Reputation: 23

GoogleAppsScript | setPictureFill doesn't work in Google Slides

This is my code. I'm trying to set a background by URL in GoogleSlides, but when I run the code, Google returns TypeError: The setPictureFill function can not be found in the Page object.

var slide = SlidesApp.getActivePresentation().getSelection().getCurrentPage();
var img = 'https://media.giphy.com/media/9bTjZrytydVRK/giphy.gif';
slide.setPictureFill(img);

Upvotes: 1

Views: 148

Answers (1)

P Burke
P Burke

Reputation: 1772

In your code slide is page object, but page objects do not have a setPictureFill() method;hence the error. What you need is a PageBackground object. Try the following:

function my_fill() {
   var slide = SlidesApp.getActivePresentation().getSelection().getCurrentPage();
   var page_background = slide.getBackground();
   var img = 'https://media.giphy.com/media/9bTjZrytydVRK/giphy.gif';
   page_background.setPictureFill(img);
}

Which successfully pulls the animated space GIF as the background.

Upvotes: 1

Related Questions