Indent Paragraph in a Google Document - Google Apps Script
Asked Answered
H

1

5

I'm trying to indent a paragraph with Google Apps Script - just a normal indent. It should be the easiest thing in the world but is proving to be extremely frustrating.

The below is the relevant section of the code I'm calling, and keep in mind everything else I'm doing (underlining, setting bold etc) is working perfectly.

function AppendDocument(){
    var doc = DocumentApp.openById('____________________');
    var body = doc.getBody();
    var myParagraph = body.appendParagraph("Hello This is a paragraph - I want to indent this please");
    myParagraph.setUnderline(true); //<-- Things like this work fine
    myParagraph.setIndentStart(72.0); //I just randomly chose 72. No number is working.
}
Homage answered 18/9, 2020 at 10:4 Comment(0)
W
7

You need to define all the indentation parameters:

myParagraph.setIndentFirstLine(72);
myParagraph.setIndentStart(72);
myParagraph.setIndentEnd(72*2);

Keep in mind that the arguments you are passing are in typographic points. See below why I used 72 as the base number.


If you click on the identation options here:

example

you will see how the indentation options are defined via the UI:

example2

You can then get a sense how you can define them in Google Apps Script. You just need to get the conversion right. In the UI, you define the indentation length using inches. In order to find the precise conversion between typographic points and inches you can google it:

1 inch (UI) = 72 typographic points (Google Apps Script)
Weeny answered 18/9, 2020 at 10:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.