Class InlineDrawing

InlineDrawing

An element representing an embedded drawing. An InlineDrawing can be contained within a ListItem or Paragraph , unless the ListItem or Paragraph is within a FootnoteSection . An InlineDrawing cannot itself contain any other element. For more information on document structure, see the guide to extending Google Docs .

Methods

Method Return type Brief description
InlineDrawing Returns a detached, deep copy of the current element.
String Returns the drawing's alternate description.
String Returns the drawing's alternate title.
Object Retrieves the element's attributes.
Element Retrieves the element's next sibling element.
ContainerElement Retrieves the element's parent element.
Element Retrieves the element's previous sibling element.
ElementType Retrieves the element's ElementType .
Boolean Determines whether the element is at the end of the Document .
InlineDrawing Merges the element with the preceding sibling of the same type.
InlineDrawing Removes the element from its parent.
InlineDrawing Sets the drawing's alternate description.
InlineDrawing Sets the drawing's alternate title.
InlineDrawing Sets the element's attributes.

Detailed documentation

copy()

Returns a detached, deep copy of the current element.

Any child elements present in the element are also copied. The new element doesn't have a parent.

Return

InlineDrawing — The new copy.

Authorization

Scripts that use this method require authorization with one or more of the following scopes :

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getAltDescription()

Returns the drawing's alternate description.

Return

String — the alternate title, or null if the element does not have an alternate title

Authorization

Scripts that use this method require authorization with one or more of the following scopes :

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getAltTitle()

Returns the drawing's alternate title.

Return

String — the alternate title, or null if the element does not have an alternate title

Authorization

Scripts that use this method require authorization with one or more of the following scopes :

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getAttributes()

Retrieves the element's attributes.

The result is an object containing a property for each valid element attribute where each property name corresponds to an item in the DocumentApp.Attribute enumeration.

 var 
  
 doc 
  
 = 
  
 DocumentApp 
 . 
 getActiveDocument 
 (); 
 var 
  
 documentTab 
  
 = 
  
 doc 
 . 
 getActiveTab 
 (). 
 asDocumentTab 
 (); 
 var 
  
 body 
  
 = 
  
 documentTab 
 . 
 getBody 
 (); 
 // 
  
 Append 
  
 a 
  
 styled 
  
 paragraph 
 . 
 var 
  
 par 
  
 = 
  
 body 
 . 
 appendParagraph 
 ( 
 'A bold, italicized paragraph.' 
 ); 
 par 
 . 
 setBold 
 ( 
 true 
 ); 
 par 
 . 
 setItalic 
 ( 
 true 
 ); 
 // 
  
 Retrieve 
  
 the 
  
 paragraph 
 ' 
 s 
  
 attributes 
 . 
 var 
  
 atts 
  
 = 
  
 par 
 . 
 getAttributes 
 (); 
 // 
  
 Log 
  
 the 
  
 paragraph 
  
 attributes 
 . 
 for 
  
 ( 
 var 
  
 att 
  
 in 
  
 atts 
 ) 
  
 { 
  
 Logger 
 . 
 log 
 ( 
 att 
  
 + 
  
 ":" 
  
 + 
  
 atts 
 [ 
 att 
 ] 
 ); 
 } 

Return

Object — The element's attributes.

Authorization

Scripts that use this method require authorization with one or more of the following scopes :

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getNextSibling()

Retrieves the element's next sibling element.

The next sibling has the same parent and follows the current element.

Return

Element — The next sibling element.

Authorization

Scripts that use this method require authorization with one or more of the following scopes :

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getParent()

Retrieves the element's parent element.

The parent element contains the current element.

Return

ContainerElement — The parent element.

Authorization

Scripts that use this method require authorization with one or more of the following scopes :

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getPreviousSibling()

Retrieves the element's previous sibling element.

The previous sibling has the same parent and precedes the current element.

Return

Element — The previous sibling element.

Authorization

Scripts that use this method require authorization with one or more of the following scopes :

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getType()

Retrieves the element's ElementType .

Use getType() to determine the exact type of a given element.

 var 
  
 doc 
  
 = 
  
 DocumentApp 
 . 
 getActiveDocument 
 (); 
 var 
  
 documentTab 
  
 = 
  
 doc 
 . 
 getActiveTab 
 () 
 . 
 asDocumentTab 
 (); 
 var 
  
 body 
  
 = 
  
 documentTab 
 . 
 getBody 
 (); 
 // 
  
 Obtain 
  
 the 
  
 first 
  
 element 
  
 in 
  
 the 
  
 active 
  
 tab 
 's body. 
 var 
  
 firstChild 
  
 = 
  
 body 
 . 
 getChild 
 ( 
 0 
 ); 
 // 
  
 Use 
  
 getType 
 () 
  
 to 
  
 determine 
  
 the 
  
 element 
 's type. 
 if 
  
 ( 
 firstChild 
 . 
 getType 
 () 
  
 == 
  
 DocumentApp 
 . 
 ElementType 
 . 
 PARAGRAPH 
 ) 
  
 { 
  
 Logger 
 . 
 log 
 ( 
 'The first element is a paragraph.' 
 ); 
 } 
  
 else 
  
 { 
  
 Logger 
 . 
 log 
 ( 
 'The first element is not a paragraph.' 
 ); 
 } 

Return

ElementType — The element type.

Authorization

Scripts that use this method require authorization with one or more of the following scopes :

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

isAtDocumentEnd()

Determines whether the element is at the end of the Document .

Return

Boolean — Whether the element is at the end of the tab.

Authorization

Scripts that use this method require authorization with one or more of the following scopes :

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

merge()

Merges the element with the preceding sibling of the same type.

Only elements of the same ElementType can be merged. Any child elements contained in the current element are moved to the preceding sibling element.

The current element is removed from the document.

 var 
  
 doc 
  
 = 
  
 DocumentApp 
 . 
 getActiveDocument 
 (); 
 var 
  
 documentTab 
  
 = 
  
 doc 
 . 
 getActiveTab 
 () 
 . 
 asDocumentTab 
 (); 
 var 
  
 body 
  
 = 
  
 documentTab 
 . 
 getBody 
 (); 
 // 
  
 Example 
  
 1 
 : 
  
 Merge 
  
 paragraphs 
 // 
  
 Append 
  
 two 
  
 paragraphs 
  
 to 
  
 the 
  
 document 
 's active tab. 
 var 
  
 par1 
  
 = 
  
 body 
 . 
 appendParagraph 
 ( 
 'Paragraph 1.' 
 ); 
 var 
  
 par2 
  
 = 
  
 body 
 . 
 appendParagraph 
 ( 
 'Paragraph 2.' 
 ); 
 // 
  
 Merge 
  
 the 
  
 newly 
  
 added 
  
 paragraphs 
  
 into 
  
 a 
  
 single 
  
 paragraph 
 . 
 par2 
 . 
 merge 
 (); 
 // 
  
 Example 
  
 2 
 : 
  
 Merge 
  
 table 
  
 cells 
 // 
  
 Create 
  
 a 
  
 two 
 - 
 dimensional 
  
 array 
  
 containing 
  
 the 
  
 table 
 's cell contents. 
 var 
  
 cells 
  
 = 
  
 [ 
 [ 
 'Row 1, Cell 1' 
 , 
  
 'Row 1, Cell 2' 
 ], 
 [ 
 'Row 2, Cell 1' 
 , 
  
 'Row 2, Cell 2' 
 ] 
 ]; 
 // 
  
 Build 
  
 a 
  
 table 
  
 from 
  
 the 
  
 array 
 . 
 var 
  
 table 
  
 = 
  
 body 
 . 
 appendTable 
 ( 
 cells 
 ); 
 // 
  
 Get 
  
 the 
  
 first 
  
 row 
  
 in 
  
 the 
  
 table 
 . 
  
 var 
  
 row 
  
 = 
  
 table 
 . 
 getRow 
 ( 
 0 
 ); 
 // 
  
 Get 
  
 the 
  
 two 
  
 cells 
  
 in 
  
 this 
  
 row 
 . 
 var 
  
 cell1 
  
 = 
  
 row 
 . 
 getCell 
 ( 
 0 
 ); 
 var 
  
 cell2 
  
 = 
  
 row 
 . 
 getCell 
 ( 
 1 
 ); 
 // 
  
 Merge 
  
 the 
  
 current 
  
 cell 
  
 into 
  
 its 
  
 preceding 
  
 sibling 
  
 element 
 . 
 var 
  
 merged 
  
 = 
  
 cell2 
 . 
 merge 
 (); 

Return

InlineDrawing — The merged element.

Authorization

Scripts that use this method require authorization with one or more of the following scopes :

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

removeFromParent()

Removes the element from its parent.

 var 
  
 doc 
  
 = 
  
 DocumentApp 
 . 
 getActiveDocument 
 (); 
 var 
  
 documentTab 
  
 = 
  
 doc 
 . 
 getActiveTab 
 (). 
 asDocumentTab 
 () 
 var 
  
 body 
  
 = 
  
 documentTab 
 . 
 getBody 
 (); 
 // 
  
 Remove 
  
 all 
  
 images 
  
 in 
  
 the 
  
 active 
  
 tab 
 ' 
 s 
  
 body 
 . 
 var 
  
 imgs 
  
 = 
  
 body 
 . 
 getImages 
 (); 
 for 
  
 ( 
 var 
  
 i 
  
 = 
  
 0 
 ; 
  
 i 
 < 
 imgs 
 . 
 length 
 ; 
  
 i 
 ++ 
 ) 
  
 { 
  
 imgs 
 [ 
 i 
 ] 
 . 
 removeFromParent 
 (); 
 } 

Return

InlineDrawing — The removed element.

Authorization

Scripts that use this method require authorization with one or more of the following scopes :

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

setAltDescription(description)

Sets the drawing's alternate description. If the given title is null , sets the description to the empty string.

Parameters

Name Type Description
description
String the alternate title

Return

InlineDrawing — the current object

Authorization

Scripts that use this method require authorization with one or more of the following scopes :

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

setAltTitle(title)

Sets the drawing's alternate title. If the given title is null , sets the title to the empty string.

Parameters

Name Type Description
title
String the alternate title

Return

InlineDrawing — the current object

Authorization

Scripts that use this method require authorization with one or more of the following scopes :

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

setAttributes(attributes)

Sets the element's attributes.

The specified attributes parameter must be an object where each property name is an item in the DocumentApp.Attribute enumeration and each property value is the new value to be applied.

 var 
  
 doc 
  
 = 
  
 DocumentApp 
 . 
 getActiveDocument 
 (); 
 var 
  
 documentTab 
  
 = 
  
 doc 
 . 
 getActiveTab 
 () 
 . 
 asDocumentTab 
 (); 
 var 
  
 body 
  
 = 
  
 documentTab 
 . 
 getBody 
 (); 
 // 
  
 Define 
  
 a 
  
 custom 
  
 paragraph 
  
 style 
 . 
 var 
  
 style 
  
 = 
  
 {}; 
 style 
 [ 
 DocumentApp 
 . 
 Attribute 
 . 
 HORIZONTAL_ALIGNMENT 
 ] 
  
 = 
  
 DocumentApp 
 . 
 HorizontalAlignment 
 . 
 RIGHT 
 ; 
 style 
 [ 
 DocumentApp 
 . 
 Attribute 
 . 
 FONT_FAMILY 
 ] 
  
 = 
  
 'Calibri' 
 ; 
 style 
 [ 
 DocumentApp 
 . 
 Attribute 
 . 
 FONT_SIZE 
 ] 
  
 = 
  
 18 
 ; 
 style 
 [ 
 DocumentApp 
 . 
 Attribute 
 . 
 BOLD 
 ] 
  
 = 
  
 true 
 ; 
 // 
  
 Append 
  
 a 
  
 plain 
  
 paragraph 
 . 
 var 
  
 par 
  
 = 
  
 body 
 . 
 appendParagraph 
 ( 
 'A paragraph with custom style.' 
 ); 
 // 
  
 Apply 
  
 the 
  
 custom 
  
 style 
 . 
 par 
 . 
 setAttributes 
 ( 
 style 
 ); 

Parameters

Name Type Description
attributes
Object The element's attributes.

Return

InlineDrawing — The current element.

Authorization

Scripts that use this method require authorization with one or more of the following scopes :

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents