Currently retrieving images like this:
var body = DocumentApp.getActiveDocument().getBody();
var styles = {};
styles[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] = DocumentApp.HorizontalAlignment.CENTER;
var imgs = body.getImages();
imgs[0].getParent().setAttributes(styles);
Is there some attribute I can add to place line breaks before image? Or maybe get the index of image and add line breaks.
Thanks in advance.
About Is there some attribute I can add to place line breaks before image?
, unfortunately, I couldn't find the attribute for directly achieving your goal. So in this case, I would like to propose maybe get the index of image and add line breaks.
. When this is reflected to the script, it becomes as follows.
var body = DocumentApp.getActiveDocument().getBody();
var image = body.getImages()[0];
var index = body.getChildIndex(image.getParent());
body.insertParagraph(index, "\n")
DocumentApp.getActiveDocument().getBody().getImages()[0].getParent().asParagraph().appendText("\n")
.
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.