The following Google Apps Script is designed to search the body of a Google Doc for a specific string/pattern (i.e. a keyword) and insert an image in place of it, optionally making it a clickable hyperlink too.
Instructions
In this example the code is designed to sit behind the Google Doc so it is bound to it. There are 4 pieces of information to complete in order to setup the script:
- searchText - this is the unique string/pattern in the Doc that you want to replace with an image e.g. "<<keyword>>"
- imageURL - this is the direct link to the image in Google Drive that you wish to use in the Doc.
- size - a numerical value representing the number of pixels for the image's width/height.
- hyperlinkURL - if you want the image to be clickable then provide a link for it.