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:
- If text is left, create a new slide with a text box (or table) which spans the entire page
- Add list items to the container as long as they still fit into it
- 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.