Object reference
Document
A DocumentApp.Document is the Google Doc file itself. In a bound script, getActiveDocument().getBody() reaches the active tab; in a standalone script, openById(id).getBody() uses the first tab.
DocumentApp.DocumentStart here
Get this object first
For a script opened from a Google Doc, call DocumentApp.getActiveDocument() to work with that open file; its getBody() method uses the active tab. In a standalone script, call DocumentApp.openById(id), where getBody() uses the first tab or getTab(tabId) selects a specific tab.
function showDocumentTitle() {
const document = DocumentApp.getActiveDocument();
Logger.log(document.getName());
} Then use it
Common actions
Choose an action, then open its example only when you need the code.
Count characters in the active tab
This records only the character count in the active tab’s body. It does not copy document text into the execution log or edit the document.
DocumentApp.DocumentShow example code
function logDocumentCharacterCount() {
const document = DocumentApp.getActiveDocument();
Logger.log('Character count: ' + document.getBody().getText().length);
} Log the document URL and paragraph count
This reads the Google Doc URL with getUrl() and counts the paragraphs in getBody() without modifying the document.
DocumentApp.DocumentDocumentApp.BodyShow example code
function logDocumentUrlAndParagraphs() {
const document = DocumentApp.getActiveDocument();
const paragraphs = document.getBody().getParagraphs().length;
Logger.log(document.getUrl() + ' (' + paragraphs + ' paragraphs)');
} Check whether a placeholder appears in the body
This searches the active tab body with findText() and logs whether {{Name}} is present without modifying the document.
DocumentApp.DocumentDocumentApp.BodyShow example code
function checkForNamePlaceholder() {
const document = DocumentApp.getActiveDocument();
const match = document.getBody().findText('\{\{Name\}\}');
Logger.log(match ? 'Found {{Name}} placeholder' : 'No {{Name}} placeholder found');
} Technical reference
Exact names and signatures
Generated runtime and signature facts stay separate from the beginner actions above. Open method details only when you need them.
At a glance
- Service
- DocumentApp
- Reference symbol
DocumentApp.Document- Object
Document- Runtime
- From signature data
Methods and signatures
Browse 40 methods
addBookmark
- addBookmark(position: DocumentApp.Position): DocumentApp.Bookmark
addEditor
- addEditor(email: string): DocumentApp.Document
- addEditor(user: User): DocumentApp.Document
addEditors
- addEditors(emailAddresses: string[]): DocumentApp.Document
addFooter
- addFooter(): DocumentApp.FooterSection
addHeader
- addHeader(): DocumentApp.HeaderSection
addNamedRange
- addNamedRange(name: string, range: DocumentApp.Range): DocumentApp.NamedRange
addViewer
- addViewer(emailAddress: string): DocumentApp.Document
- addViewer(user: User): DocumentApp.Document
addViewers
- addViewers(emailAddresses: string[]): DocumentApp.Document
getActiveTab
- getActiveTab(): DocumentApp.Tab | null
getAs
- getAs(contentType: string): Blob
getBlob
- getBlob(): Blob
getBody
- getBody(): DocumentApp.Body
getBookmark
- getBookmark(id: string): DocumentApp.Bookmark | null
getBookmarks
- getBookmarks(): DocumentApp.Bookmark[]
getCursor
- getCursor(): DocumentApp.Position | null
getEditors
- getEditors(): User[]
getFooter
- getFooter(): DocumentApp.FooterSection | null
getFootnotes
- getFootnotes(): DocumentApp.Footnote[]
getHeader
- getHeader(): DocumentApp.HeaderSection | null
getId
- getId(): string
getLanguage
- getLanguage(): string | null
getName
- getName(): string
getNamedRangeById
- getNamedRangeById(id: string): DocumentApp.NamedRange | null
getNamedRanges
- getNamedRanges(): DocumentApp.NamedRange[]
- getNamedRanges(name: string): DocumentApp.NamedRange[]
getSelection
- getSelection(): DocumentApp.Range | null
getSupportedLanguageCodes
- getSupportedLanguageCodes(): string[]
getTab
- getTab(tabId: string): DocumentApp.Tab | null
getTabs
- getTabs(): DocumentApp.Tab[]
getUrl
- getUrl(): string
getViewers
- getViewers(): User[]
newPosition
- newPosition(element: DocumentApp.Element, offset: number): DocumentApp.Position
newRange
- newRange(): DocumentApp.RangeBuilder
removeEditor
- removeEditor(emailAddress: string): DocumentApp.Document
- removeEditor(user: User): DocumentApp.Document
removeViewer
- removeViewer(emailAddress: string): DocumentApp.Document
- removeViewer(user: User): DocumentApp.Document
saveAndClose
- saveAndClose(): void
setActiveTab
- setActiveTab(tabId: string): void
setCursor
- setCursor(position: DocumentApp.Position): DocumentApp.Document
setLanguage
- setLanguage(languageCode: string): DocumentApp.Document
setName
- setName(name: string): DocumentApp.Document
setSelection
- setSelection(range: DocumentApp.Range): DocumentApp.Document
Need the whole workflow?
Return to a task guide
Task guides cover setup, permissions, expected results, and troubleshooting as well as object methods.
Browse Google Docs tasks