Google Apps Script
Feedback on this document

Class InlineImage

An element representing an embedded image.

InlineImages may only be contained within Paragraphs.

Methods

MethodReturn typeBrief description
copy()InlineImageReturns a detached, deep copy of the current element.
getAs(contentType)CompositeBlobReturn the data inside this object as a Blob converted to the specified content type.
getAttributes()ObjectRetrieves the element's attributes.
getBlob()BlobReturn the data inside this object as a Blob.
getHeight()IntegerRetrieves the image's height, in pixels.
getNextSibling()ElementRetrieves the next sibling InlineImage.
getParent()ContainerElementRetrieves the element's parent InlineImage.
getPreviousSibling()ElementRetrieves the previous sibling InlineImage.
getType()ElementTypeRetrieves the element's ElementType.
getWidth()IntegerRetrieves the image's width, in pixels.
isAtDocumentEnd()BooleanDetermines whether the element is at the end of the Document.
merge()InlineImageMerges the element with the preceding sibling of the same type.
removeFromParent()InlineImageRemoves the element from its parent.
setAttributes(attributes)InlineImageSets the element's attributes.
setHeight(height)InlineImageSets the image's height, in pixels.
setWidth(width)InlineImageSets the image's width, in pixels.

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 will not have a parent.

Return

InlineImage — the new copy


getAs(contentType)

Return the data inside this object as a Blob converted to the specified content type.

Parameters

NameTypeDescription
contentTypeStringthe MIME type to convert to. For most blobs, 'application/pdf' is the only valid option. For images in BMP, GIF, JPEG, or PNG format, any of 'image/bmp', 'image/gif', 'image/jpeg', or 'image/png' are also valid.

Return

CompositeBlob — the data as a blob


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();

 // Append a styled paragraph.
 var par = doc.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


getBlob()

Return the data inside this object as a Blob.

Return

Blob — the data as a blob


getHeight()

Retrieves the image's height, in pixels.

Return

Integer — the image's height, in pixels


getNextSibling()

Retrieves the next sibling InlineImage.

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

Return

Element — the next sibling element


getParent()

Retrieves the element's parent InlineImage.

The parent element contains the current element.

Return

ContainerElement — the parent element


getPreviousSibling()

Retrieves the previous sibling InlineImage.

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

Return

Element — the previous sibling element


getType()

Retrieves the element's ElementType.

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

 var doc = DocumentApp.getActiveDocument();

 // Obtain the first element in the document body.

 var firstChild = doc.getChild(0);

 // Use geType() 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


getWidth()

Retrieves the image's width, in pixels.

Return

Integer — the image's width, in pixels


isAtDocumentEnd()

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

Return

Boolean — whether the element is at the end of the document


merge()

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

Only elements of the same ElementType may 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();

 // Append two paragraphs to the document.
 var par1 = doc.appendParagraph('Paragraph 1.');
 var par2 = doc.appendParagraph('Paragraph 2.');

 // Merge the newly added paragraphs into a single paragraph.
 par2.merge();
 

Return

InlineImage — the merged element


removeFromParent()

Removes the element from its parent.

 var doc = DocumentApp.getActiveDocument();

 // Remove all images in the document body.
 var imgs = doc.getImages();
 for (var i = 0; i < imgs.length; i++) {
   imgs[i].removeFromParent();
 }
 

Return

InlineImage — the removed element


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();

 // Define a custom paragraph style.
 var style = {};
 style[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] =
     DocumentApp.HorizontalAlignment.RIGHT;
 style[DocumentApp.Attribute.FONT_FAMILY] =
     DocumentApp.FontFamily.CALIBRI;
 style[DocumentApp.Attribute.FONT_SIZE] = 18;
 style[DocumentApp.Attribute.BOLD] = true;

 // Append a plain paragraph.
 var par = doc.appendParagraph('A paragraph with custom style.');

 // Apply the custom style.
 par.setAttributes(style);
 

Parameters

NameTypeDescription
attributesObjectthe element's attributes

Return

InlineImage — the current element


setHeight(height)

Sets the image's height, in pixels.

Parameters

NameTypeDescription
heightIntegerthe image's height, in pixels

Return

InlineImage — the current element


setWidth(width)

Sets the image's width, in pixels.

Parameters

NameTypeDescription
widthIntegerthe image's width, in pixels

Return

InlineImage — the current element

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.