How to make in-line images vertically aligned with text?
Asked Answered
H

1

7

I am looking for a way to make in-line images vertically aligned so that the center of the in-line image vertically is aligned with the center of the text vertically. Currently, the bottom edge of the in-line images is flush with the bottom of the text. As a result, it seems like the images are much higher than they should be. Does anyone know if there's a way to control this from inside Google apps script, or any plans for development?

For instance, I want the in-line image on the 1st line in this Google Docs to look like the wrapped image on the 2nd line: Vertically aligned images

Hoch answered 20/10, 2016 at 22:37 Comment(2)
Have you tried using setAttributes(attributes)? It has a HORIZONTAL_ALIGNMENT property that might help achieve that goal.Lauderdale
Yes, that setting is meant to be for the text alignment, for instance, right justified or left justified.Hoch
E
1

You would use the PositionedImage class to do this. WRAP_TEXT format should put your image inline, but you can still further fine tune using the various offset methods. https://developers.google.com/apps-script/reference/document/positioned-image

//EXAMPLE Modified from Apps Script Documentation

var body = DocumentApp.getActiveDocument().getBody();

 // Append a new paragraph.
 var paragraph = body.appendParagraph("New paragraph to anchor the image to.");

 // Get an image in Drive from its ID.
 var image = DriveApp.getFileById('ENTER_IMAGE_FILE_ID_HERE').getBlob();

 // Add the PositionedImage with WRAP_TEXT Layout
 var posImage = paragraph.addPositionedImage(image)
                            .setLayout(DocumentApp.PositionedLayout.WRAP_TEXT)
Eve answered 21/10, 2016 at 13:27 Comment(1)
I want the image to go after some certain text(for instance, referring to the image in my question, the Google image should go right after the word in), and there's no way to find this exact position with this class.Hoch

© 2022 - 2024 — McMap. All rights reserved.