0

Here's my current code:

var NAME = "My favorite images";
var deck = SlidesApp.openById("1DKsiDGX9wwRbgP9WH2IJL2- 
    b1u1Q6jjz0JbrrKd_Fl4 ");

    /**
      * Creates a single slide using the image from the given link;
      * used directly by foreach(), hence the parameters are fixed.
      *
      * @param {Date} link A String object representing an image URL
      * @param {Date} index The index into the array; unused (req'd by 
        forEach)
      */
    function addImageSlide(imageUrl, index) {
      var slide = deck.appendSlide(SlidesApp.PredefinedLayout.BODY);
      var image = slide.insertImage(imageUrl);
      var imgWidth = image.getWidth();
      var imgHeight = image.getHeight();
      var pageWidth = deck.getPageWidth();
      var pageHeight = deck.getPageHeight();
      var newX = pageWidth / 2. - imgWidth / 2.;
      var newY = pageHeight / 2. - imgHeight / 2.;
      image.setLeft(newX).setTop(newY);
    }

    /**
      * The driver application features an array of image URLs, setting 
        of the
      * main title & subtitle, and creation of individual slides for each 
        image.
      */
    function main() {
      var images = [
        "http://www.google.com/services/images/phone-animation- 
        results_2x.png ",
        "http://www.google.com/services/images/section-work-card- 
        img_2x.jpg ",
        "http://gsuite.google.com/img/icons/product-lockup.png",
        "http://gsuite.google.com/img/home-hero_2x.jpg"
      ];
      var [title, subtitle] = deck.getSlides()[0].getPageElements();
      title.asShape().getText().setText(NAME);
      subtitle.asShape().getText().setText("");
      images.forEach(addImageSlide);
    }

I keep getting the error Cannot find method appendSlide((class)). (line 12, file "Code") What changes should I make to be able to insert URLs of images so that they can be inserted into an existing google slides template?

Rubén
  • 34,714
  • 9
  • 70
  • 166
jack law
  • 11
  • 2

1 Answers1

0

As per documentation here there is no predefined layout called SlidesApp.PredefinedLayout.BODY. Hence you get that error. If you change the layout to blank, for instance, this code works fine.

Please modify this line 12, like so:

var slide = deck.appendSlide(SlidesApp.PredefinedLayout.BODY);

var slide = deck.appendSlide(SlidesApp.PredefinedLayout.BLANK);
Jack Brown
  • 5,802
  • 2
  • 12
  • 27
  • Yea i found that works. However, I have custom layouts in the template I created. How do I use those layouts? – jack law Mar 22 '18 at 06:21