“I want to automatically insert descriptions and annotations into reports created with Google Slides using Google Apps Script.”
“I want to automatically insert monthly executive summaries into fixed positions across my regular presentation decks.”
When manually building presentations, creating a text box is an indispensable first step whenever you need to write sentences. By leveraging Google Apps Script (GAS), you can completely automate the entire process—from generating text boxes and typing text to setting their precise coordinates on your slides.
In our previous lessons ([Part 64] / [Part 65]), we learned how to draw shapes such as rectangles and circles, as well as how to customize background colors and borders. In this tutorial, we will take a deep dive into Slide.insertTextBox(), one of the most frequently used methods for slide automation!
Using a “Sapporo Office Monthly Performance Report” as our practical project, we will write code to position a “Monthly Highlights & Summary” text box precisely where we want it. Along the way, we’ll cover basic syntax, layout coordinate tips, and common pitfalls beginners often encounter.
1. What Is Slide.insertTextBox() in Google Apps Script?
Slide.insertTextBox() is a built-in GAS method that creates and inserts a new text box (a container for text entry) onto a specified slide canvas (a Slide object).
Understanding the Hierarchy: The “House, Room, and Furniture” Analogy
Let’s review our familiar “House, Room, and Furniture” analogy by mapping it to Google Slides manipulation in Phase 7.
- [House] = The Entire Presentation File (
Presentation)
This corresponds to the presentation file object itself, retrieved usingSlidesApp.openById()as covered in [Part 61]. - [Room] = Individual Slide Pages (
Slide)
This represents each individual slide canvas that you duplicate or select, as seen in [Part 63]. - [Furniture & Displays] = Text Boxes, Shapes, and Images (
PageElement/Shape)
★Our main focus today! Text boxes placed on a slide act like message boards mounted on the walls of a room.
In short, executing Slide.insertTextBox() corresponds to “mounting a new message board (text box) onto the wall of a designated room (slide).”
2. Two Syntax Options for Slide.insertTextBox()
insertTextBox() provides two distinct syntax patterns depending on your specific layout requirements.
Pattern 1: Specifying Text Only (Simple Placement)
var textBox = slide.insertTextBox("Text you want to insert");
- Description: The minimal syntax where you only pass the string you wish to display.
- Behavior: Automatically placed near the center of the slide with default dimensions matching the text length.
- Best Used When: You don’t need exact positioning and simply want to output text onto the canvas quickly.
Pattern 2: Specifying Text, Position, and Dimensions (Fixed Positioning – Recommended!)
var textBox = slide.insertTextBox("Text you want to insert", left, top, width, height);
- Description: In addition to the text, you strictly define the exact position (
left,top) and dimensions (width,height) using numeric values. - Best Used When: Creating report templates or automated slides where elements must fit into a standardized layout.
3. STEP 1: Set Up the “Sapporo Office Monthly Performance Report” Presentation
First, let’s create a Google Slides presentation to practice our GAS automation.
Setup Steps
- Open Google Drive, click “+ New” in the upper-left corner, and select “Google Slides” to create a blank presentation.
- Rename the file to “Sapporo Office Monthly Performance Report”.
- In the title box of the first slide, type “Sapporo Office Monthly Results Report”.
- Retrieve the Slide ID (Presentation ID). From your browser’s address bar, copy the alphanumeric ID string highlighted below:
https://docs.google.com/presentation/d/1ABC123xyz_ExampleID_xxxxxxxxxxxx/edit
Setup is now complete!
4. STEP 2: Practice Inserting a “Monthly Highlights” Text Box with GAS
Now, let’s open the Google Apps Script editor and write the code.
Whether from an attached Google Spreadsheet or a standalone script editor, open the presentation you created and add a “Monthly Highlights” text box to a specific position on the slide.
1. Enter the Code
Open the GAS editor, clear out any existing code, and paste the following script.
Make sure to replace YOUR_PRESENTATION_ID_HERE with the ID you copied in STEP 1.
function addTopicsTextBox() {
// ① From [Part 61]: Open the presentation by ID (Get the House)
var presentationId = "YOUR_PRESENTATION_ID_HERE";
var presentation = SlidesApp.openById(presentationId);
// ② Get the first slide (Get the Room)
var slide = presentation.getSlides()[0];
// ③ Prepare the body text to insert
var topicsText = "[Monthly Highlights (Sapporo Office)]\n" +
"- The newly established Sapporo AI Development Team achieved an operating rate of 120%.\n" +
"- The seminar satisfaction rate for local businesses reached 98%, leading to new project leads.";
// ④ Insert the text box with specific coordinates and dimensions (Place the Furniture)
// Arguments: (text, X coordinate [Left], Y coordinate [Top], Width, Height)
var left = 50; // Distance from the left edge (points)
var top = 180; // Distance from the top edge (points)
var width = 600; // Text box width (points)
var height = 120; // Text box height (points)
var textBox = slide.insertTextBox(topicsText, left, top, width, height);
// ⑤ Confirm in execution log
Logger.log("Text box successfully placed! Element type: " + textBox.getPageElementType());
}
2. Save and Run the Script
- Click Save (the disk icon) at the top of the editor.
- Ensure the function dropdown is set to
addTopicsTextBox, then click the Run button. - If prompted for permissions upon first run, follow the dialogs to authorize the script (see [Part 2] for details).
3. Check the Results
Switch over to your Google Slides presentation and take a look!
Below the title (“Sapporo Office Monthly Results Report”) around top: 180, you should see a wide text box containing “[Monthly Highlights (Sapporo Office)]…” positioned cleanly on the slide!
5. STEP 3: Coordinate (Left/Top) and Sizing (Width/Height) Rules Explained
When manipulating designs and visual layouts programmatically, understanding coordinate systems and units of measurement is critical.
1. The Coordinate Axis: Origin is Top-Left
Positions in Google Slides are calculated on a 2D plane with the top-left corner of the slide serving as the origin $(X=0, Y=0)$.
(0,0) Top-Left Origin ─────────────────────────┐
│ │
│ ← left → ┌──────────────┐ │
│ ▲ │ Text │ │
│ top │ Box │ height │
│ ▼ └──────────────┘ │
│ ← width → │
│ │
└───────────────────────────────────────────┘
left(X coordinate): Distance from the left edge of the slide to the left edge of the text box.top(Y coordinate): Distance from the top edge of the slide to the top edge of the text box.width: Horizontal width of the text box itself.height: Vertical height of the text box itself.
2. Unit of Measurement: Points (pt)
In Google Apps Script, measurements for positioning and sizing slide elements are specified in points (pt).
- $1 \text{ inch} = 72 \text{ pt}$
- The standard 16:9 widescreen presentation in Google Slides has a width of 720 pt and a height of 405 pt.
If you’re unsure where to position elements, use these typical guideline values to arrange your layout:
| Screen Area | Recommended left (pt) | Recommended top (pt) |
| Left side (split layout) | 30 – 50 | 100 – 150 |
| Right side (split layout) | 500 – 520 | 100 – 150 |
| Bottom area (footer/summary) | 50 – 100 | 400 – 450 |
6. Practical Applications: Utilizing the insertTextBox() Return Value
When you execute slide.insertTextBox(), it returns a Shape object.
You might wonder: “Why does creating a text box return a Shape?” In Google Slides’ internal architecture, a text box is treated as a rectangular shape with a transparent background and no border.
Because of this, you can directly apply shape styling methods learned in previous tutorials to your newly created text box.
// Create the text box
var textBox = slide.insertTextBox("Important Note", 50, 100, 300, 80);
// From [Part 65]: Set the background fill to pastel yellow
textBox.getFill().setSolidFill("#fff2cc");
// From [Part 65]: Set the border line color to gray
textBox.getBorder().getLineFill().setSolidFill("#cccccc");
By applying fills and borders to a box created with insertTextBox(), you can instantly turn it into an attention-grabbing callout card or highlight box!
7. 5 Common Traps for Beginners and How to Fix Them
Here are five frequent stumbling blocks beginners encounter when working with Slide.insertTextBox(), along with clear solutions for each.
Trap 1: Calling It on Presentation Instead of Slide (TypeError)
// ✕ Incorrect: Calling directly on the Presentation object
var presentation = SlidesApp.openById("ID");
presentation.insertTextBox("Message");
// Error: TypeError: presentation.insertTextBox is not a function
Cause & Solution:
insertTextBox() is not a method of the top-level presentation file (Presentation); it belongs to individual slide instances (Slide). Always extract the target slide (room) first using methods like presentation.getSlides()[0] before calling it.
Trap 2: Mixing Up the Argument Order
// ✕ Incorrect: Swapping top and left coordinates
slide.insertTextBox("Text", top, left, height, width);
Cause & Solution:
The argument order is strict and non-negotiable.
Always remember the sequence: (text, left, top, width, height)—Text first, then Left, Top, Width, Height.
Trap 3: Box Dimensions Are Too Small, Causing Text Overflow
If your text contains many characters but you assign a small width or height, the text may overflow or wrap awkwardly, spoiling your presentation’s visual polish.
Solution:
When inserting longer passages, allocate a generous width (e.g., 500–700 pt) or insert explicit newline characters (\n) at intentional breakpoints.
Trap 4: Duplicate Elements Stacking Over Each Other
If you test-run your script repeatedly, a new text box will be created at the exact same coordinates (e.g., left: 50, top: 180) each time, creating stacked duplicates that clutter your canvas.
Solution:
During development, either delete obsolete elements manually between runs or add a cleanup routine at the start of your script to purge existing elements (which we’ll cover in an upcoming lesson).
Trap 5: Trying to Change Font Sizes and Colors Directly via insertTextBox()
You might think: “I created the text box, but how do I increase the font size or highlight ‘120%’ in bold red?”
The arguments for insertTextBox() only accept plain text strings. To style text characters, change fonts, or apply text colors, you need to extract and manipulate the TextRange object from your text box.
Summary & What’s Coming Next
In this lesson, we explored how to use Slide.insertTextBox() to position automated text boxes anywhere on a Google Slide canvas.
Key Takeaways
Slide.insertTextBox()creates a new text container on a slide.- Precise positioning requires 5 arguments:
(text, left, top, width, height). - Coordinates start from the top-left corner $(0,0)$, measured in points (pt).
- The return value is a
Shapeobject, allowing background and border styling.
Now you have full control over inserting text boxes into your presentations programmatically!
Next, you’ll likely want to know: “How do I format the text inside, make specific words bold, or highlight key metrics with eye-catching colors?”
In our next tutorial (Part 67), we will explore TextRange.setText() and setFontSize()!
We’ll discover how to dynamically edit content inside text boxes and dramatically scale up important numbers like “120% Achievement” for maximum visual impact. Stay tuned!
