Class PositionedImage

PositionedImage

Fixed position image anchored to a Paragraph. Unlike an InlineImage, a PositionedImage is not an Element. It does not have a parent or sibling Element. Instead, it is anchored to a Paragraph or ListItem, and is placed via offsets from that anchor. A PositionedImage has an ID that can be used to reference it.


 var body = DocumentApp.getActiveDocument().getBody();

 // Append a new paragraph.
 var paragraph = body.appendParagraph("New paragraph to anchor the image to.");
 *
 // Get an image in Drive from its ID.
 var image = DriveApp.getFileById('ENTER_IMAGE_FILE_ID_HERE').getBlob();

 // Add the PositionedImage with offsets (in points).
 var posImage = paragraph.addPositionedImage(image)
     .setTopOffset(60)
     .setLeftOffset(40);
 

Methods

MethodReturn typeBrief description
getAs(contentType)BlobReturn the data inside this object as a blob converted to the specified content type.
getBlob()BlobReturn the data inside this object as a blob.
getHeight()IntegerRetrieves the image's height, in pixels.
getId()StringGets the image's ID.
getLayout()PositionedLayoutGets an enum value that represents how the image is laid out.
getLeftOffset()NumberGets the image's offset, in points, from the paragraph's left.
getParagraph()ParagraphGets the Paragraph the image is anchored to.
getTopOffset()NumberGets the image's offset, in points, from the paragraph's top.
getWidth()IntegerRetrieves the image's width, in pixels.
setHeight(height)PositionedImageSets the image's height, in pixels.
setLayout(layout)PositionedImageSets the definition of how the image is laid out.
setLeftOffset(offset)PositionedImageSets the image's offset, in points, from the paragraph's left.
setTopOffset(offset)PositionedImageSets the image's offset, in points, from the paragraph's top.
setWidth(width)PositionedImageSets the image's width, in pixels.

Detailed documentation

getAs(contentType)

Return the data inside this object as a blob converted to the specified content type. This method adds the appropriate extension to the filename — for example, "myfile.pdf". However, it assumes that the part of the filename that follows the last period (if any) is an existing extension that should be replaced. Consequently, "ChristmasList.12.25.2014" will become "ChristmasList.12.25.pdf".

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

Blob — the data as a blob


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


getId()

Gets the image's ID.

Return

String — the image ID


getLayout()

Gets an enum value that represents how the image is laid out.

Return

PositionedLayout — the image layout


getLeftOffset()

Gets the image's offset, in points, from the paragraph's left.

Return

Number — the image offset from the left paragraph's left


getParagraph()

Gets the Paragraph the image is anchored to.

Return

Paragraph — the parent paragraph


getTopOffset()

Gets the image's offset, in points, from the paragraph's top.

Return

Number — the image offset from the left paragraph's top


getWidth()

Retrieves the image's width, in pixels.

Return

Integer — the image's width, in pixels


setHeight(height)

Sets the image's height, in pixels.

Parameters

NameTypeDescription
heightIntegerthe image's height, in pixels

Return

PositionedImage — the current object


setLayout(layout)

Sets the definition of how the image is laid out.

Parameters

NameTypeDescription
layoutPositionedLayoutan enum representing the layout mode

Return

PositionedImage — this object for chaining


setLeftOffset(offset)

Sets the image's offset, in points, from the paragraph's left.

Parameters

NameTypeDescription
offsetNumberoffset from the paragraph's left

Return

PositionedImage — this object for chaining


setTopOffset(offset)

Sets the image's offset, in points, from the paragraph's top.

Parameters

NameTypeDescription
offsetNumberoffset from the paragraph's top

Return

PositionedImage — this object for chaining


setWidth(width)

Sets the image's width, in pixels.

Parameters

NameTypeDescription
widthIntegerthe image's width, in pixels

Return

PositionedImage — the current object

发送以下问题的反馈:

此网页
Apps Script
Apps Script