To clear the left indentation back to default for all page elements (including paragraphs, lists, etc.) in a Google Doc using Apps Script, you can adjust the indentation attributes accordingly. Here’s a script to accomplish this:
function clearLeftIndentation() {
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
var paragraphs = body.getParagraphs();
var lists = body.getListItems();
// Clear left indentation for paragraphs
for (var i = 0; i < paragraphs.length; i++) {
var paragraph = paragraphs[i];
paragraph.setIndentStart(0);
paragraph.setIndentFirstLine(0);
}
// Clear left indentation for lists
for (var i = 0; i < lists.length; i++) {
var list = lists[i];
list.setIndentStart(0);
}
}
This script iterates through all paragraphs and lists in the document, setting their left indentation attributes to 0, effectively clearing any left indentation.
To use this script:
- Open your Google Document.
- Click on “Extensions” > “Apps Script.”
- Delete any code in the script editor and replace it with the provided script.
- Save the script.
- Run the function
clearLeftIndentation
from the script editor.
This will clear the left indentation back to default for all page elements in your document.