1

After I use Google Slide API to create slides for me, I see text box with text saying 'Click to add Text' , 'Click to add title', And same for 2 column sides, how can i set the text for the right 'Click to add Text', and same for the left.

How can I programmatically find out those text boxes and set the text I want?

Here is the code: I 1) create a slide and make it TITLE_AND_TWO_COLUMNS layout 2) create a Shape and 3) Insert Text to the Shape. But when I view the slide in google drive, i see 'Click to Add Text'

        IList<Request> requests = new List<Request>();
        String slideId = "MyNewSlide_001";
        requests.Add(new Request()
        {
            CreateSlide = new CreateSlideRequest()
            {
                ObjectId = slideId,
                InsertionIndex = 1,
                SlideLayoutReference = new LayoutReference()
                {
                    PredefinedLayout = "TITLE_AND_TWO_COLUMNS"
                }
            }
        });

        String textBoxId = "MyTextBox_01";
        Dimension pt350 = new Dimension()
        {
            Magnitude = 350.0,
            Unit = "PT",
        };
        requests.Add(new Request()
        {
            CreateShape = new CreateShapeRequest()
            {
                ObjectId = textBoxId,
                ShapeType = "TEXT_BOX",
                ElementProperties = new PageElementProperties()
                {
                    PageObjectId = slideId,
                    Size = new Size()
                    {
                        Height = pt350,
                        Width = pt350
                    },
                },
            }
        });

        requests.Add(new Request()
        {
            UpdateShapeProperties = new UpdateShapePropertiesRequest()
            {
                ObjectId = textBoxId,
                ShapeProperties = new ShapeProperties
                {
                    ShapeBackgroundFill = new ShapeBackgroundFill
                    {
                        SolidFill = new SolidFill
                        {
                            Color = new OpaqueColor
                            {
                                ThemeColor = "HYPERLINK"
                            }
                        }
                    }
                },
                Fields = "shapeBackgroundFill.solidFill.color,outline"
            },
        });

        // Insert text into the box, using the object ID given to it.
        requests.Add(new Request()
        {
            InsertText = new InsertTextRequest()
            {
                ObjectId = textBoxId,
                InsertionIndex = 0,
                Text = "New Box Text Inserted"
            }
        });
2
  • What is your code so far to create the slides? What have you tried? Commented Nov 19, 2016 at 20:20
  • @n179911 Very useful code snippet! Can I ask where did you find the documentation to write it? I could not find any code sample for the G Slides Java API. Commented Feb 25, 2019 at 9:34

1 Answer 1

2

Those boxes with "Click to add text" text are placeholder Shapes that are automatically copied onto your slide from the layout. That text is only visible in the editor: they wont have any text in present mode, unless you insert text into them directly.

You can insert text into them just like any other shapes in the Slides API.

  • Read the page or presentation with one of the GET APIs (presentations.get or presentations.pages.get)
  • Find the object IDs of the placeholders you want to write in. You can identify which is which looking at the pageElement.shape.placeholder message on each page element on your slide. You want the one with type = TITLE for the title, and so on.
  • Call batchUpdate with an insertText request to add the text, just like you're already doing in your code

Some of this is covered in the Edit text in a specified shape in the documentation.

Sign up to request clarification or add additional context in comments.

2 Comments

Is it possible to give my TITLE placeholder in a custom Layout a unique ID, so I can avoid the get step prior to the batch update? Ideally I want to: 1. create new slide from a custom layoutId 2. set the Title text all in the same batch update request, without making a get call after #1, searching for the objectId and then making a separate request to accomplish #2.
Yes -- see the placeholderIdMappings parameter on CreateSlideRequest in batchUpdate. There's some documentation for this specific usecase here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.