I have created a bookmark in Google Docs. I know the bookmark Id.
function addBookmark() {
var doc = DocumentApp.getActiveDocument();
var cursor = doc.getCursor();
var bookmark = doc.addBookmark(cursor);
var bookmarkId = bookmark.getId();
Logger.log(bookmarkId);
}
The bookmark Id is not helpful. Better is to write a paragraph with specific text in the document. Now you can search for it and add or update the image.
function updateImageAtParagraph() {
var body = DocumentApp.getActiveDocument().getBody();
// Get an image in Drive from its ID.
var image = DriveApp.getFileById('...imageId...');
var searchString = "paragraphText"; //specific text paragraph in the document
var paragraphSearch = body.findText(searchString);
if(paragraphSearch !== null) {
var paragraph = paragraphSearch.getElement().getParent().asParagraph();
paragraph.clear().appendText(searchString);
paragraph.appendInlineImage(image);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.