Getting the exact position of a location within a text box on slides?

361 views
Skip to first unread message

Yush

unread,
Aug 15, 2021, 11:33:40 PM8/15/21
to Google Apps Script Community
I want to take a certain character within a textbox and replace it with an image at that location. However, while I can get the textbox coordinates, I can't get the coords of the specific character within the textbox on the slide, so I can insert the image at that location. Does anyone know a way to do this, an issue open, or a plan for devs to implement this feature?

Jonathan Butler

unread,
Aug 16, 2021, 12:45:40 AM8/16/21
to google-apps-sc...@googlegroups.com
I'm not sure if what you are asking is possible. However, I can think of a couple of work arounds. 

First, you can break the text into two text boxes and add a shape in between. The first text box containing everything before the character you want to replace will be above the shape and the second text box containing everything after will be below the shape.Finally you can use the replace the shape with the replaceWithImage function.

Second, you could just put a shape on top of the text box and resize it small enough to block out the character. Then you can call the replaceWithImage function and the coordinates should stay the same.

On Sun, Aug 15, 2021 at 10:33 PM Yush <aayush...@gmail.com> wrote:
I want to take a certain character within a textbox and replace it with an image at that location. However, while I can get the textbox coordinates, I can't get the coords of the specific character within the textbox on the slide, so I can insert the image at that location. Does anyone know a way to do this, an issue open, or a plan for devs to implement this feature?

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/ccfac473-bdc8-41ce-9738-ce464b61b8e3n%40googlegroups.com.

Yush

unread,
Aug 16, 2021, 3:37:28 PM8/16/21
to Google Apps Script Community
I don't think the first case will work if the text is longer than one line, because the text will have to come together afterwards, there's no way of knowing where the line break is actually happening.

In the second case, replaceWithImage is a member function of the shape class, but the text classes are all textRange classes. How would I go about calling this function on a specific letter?
Reply all
Reply to author
Forward
0 new messages