0

I am having a long text with list items which I want to add to Google Slides via Apps Script. As the length of the text and the single list items may differ, I need to create multiple slides to cover the entire text.

For this purpose, I wanted to do the following:

  1. If text is left, create a new slide with a text box (or table) which spans the entire page
  2. Add list items to the container as long as they still fit into it
  3. If text is left, start over with a new slide until all text has been placed

However, this does not work:

  var slides = SlidesApp.openById("...");
  var pageHeight = slides.getPageHeight();
  var stringList = ["Long text 1", "Long text 2", "Long text 3"];
  var page = 0;

  while (stringList.length > 0) {
    var container = slides.getSlides()[page].getShapes()[0]; //some text box
    container.getText().clear();

    while (container.getHeight() < pageHeight && stringList.length > 0) {
      container.getText().appendText(stringList.shift());
    }
    page++;
  }
}

Now I am having the problem, that I did not find any way to get the actual height of an element (which the text consumes) to check whether the text still fits onto the page respectively into the container. This script would fill the single text box forever as getHeight() ignores the height of the text. Table cells grow with the text but only seem to have their minimumHeight.

So, I am looking for a way to split my text into as many slides as needed. Do you know any property, method or another approach to get to know the actual height of the text in a text box or table cell?

Of course, this would be no problem at all with a Google Doc but I also need to add some style with shapes, backgrounds and so on why this is not an option, unfortunately. The list items come from a Google Spreadsheet with one row per item.

Thank you in advance for any ideas.

Rubén
  • 34,714
  • 9
  • 70
  • 166
AdmPicard
  • 439
  • 3
  • 14
  • 1
    Please [edit](http://stackoverflow.com/posts/43463046/edit) the question to be on-topic: include a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) that duplicates the problem. Questions seeking debugging help ("why isn't this code working the way I want?") must include: (1) the desired behavior, (2) a specific problem or error and (3) the shortest code necessary to reproduce it in the question itself. Please also see: [What topics can I ask about here?](http://stackoverflow.com/help/on-topic), and [How to Ask](http://stackoverflow.com/help/how-to-ask) – Mr.Rebot Jan 10 '19 at 22:01
  • Thanks for the hint. As I am lacking an approach, it is not a debugging question. However, as a code sample certainly helps, I added one that technically works but does not yield the desired behaviour due to the mentioned problem. – AdmPicard Jan 11 '19 at 23:42
  • 1
    It is very similar to this: https://stackoverflow.com/q/53218561/4691910 However, also unanswered, unfortunately. Maybe there is no possibility right now. As a poor alternative, I'd add one text after the other, display a prompt and ask the user whether the text still fits the page. Would be annoying but I don't have another idea right now. – AdmPicard Jan 11 '19 at 23:54

0 Answers0