Replacing Text to Image for Google Document using Google Apps Script
This is a sample script for replacing text to image for Google Document using Google Apps Script (GAS). There is a method for replacing text to text at Class Text of DocumentApp. But there are not methods for replacing text to image. So I created this sample script.
Demo :
This sample image was created by k3-studio.
Usage :
replaceTextToImage(body, replaceText, image, width);
body: body of document. You can set byDocumentApp.getActiveDocument().getBody()andDocumentApp.openById(documentId).getBody().replaceText: string you want to replace.image: blob of image you want to replace.width: Width of replaced image. The aspect ratio is constant. The unit is pixels. If you don’t use this, the original size is used.
Script :
In this sample script, all strings of “sample” in the document are replaced to image with the file ID of imageFileId.