PositionedImage

Fixed position image anchored to a `https://developers.google.com/apps-script/reference/document/paragraph`. Unlike an `https://developers.google.com/apps-script/reference/document/inline-image`, a `PositionedImage` is
not an `https://developers.google.com/apps-script/reference/document/element`. It does not have a
parent or sibling `https://developers.google.com/apps-script/reference/document/element`. Instead,
it is anchored to a `https://developers.google.com/apps-script/reference/document/paragraph` or `https://developers.google.com/apps-script/reference/document/list-item`, and is placed via offsets from
that anchor. A `PositionedImage` has an ID that can be used to reference it.

```javascript
const body =
    DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody();

// Append a new paragraph.
const paragraph = body.appendParagraph('New paragraph to anchor the image to.');

// Get an image in Drive from its ID.
const image = DriveApp.getFileById('ENTER_IMAGE_FILE_ID_HERE').getBlob();

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

### Methods

| Method | Return type | Brief description |
|---|---|---|
| `https://developers.google.com/apps-script/reference/document/positioned-image#getAs(String)` | `https://developers.google.com/apps-script/reference/base/blob.html` | Return the data inside this object as a blob converted to the specified content type. |
| `https://developers.google.com/apps-script/reference/document/positioned-image#getBlob()` | `https://developers.google.com/apps-script/reference/base/blob.html` | Return the data inside this object as a blob. |
| `https://developers.google.com/apps-script/reference/document/positioned-image#getHeight()` | `Integer` | Retrieves the image's height, in pixels. |
| `https://developers.google.com/apps-script/reference/document/positioned-image#getId()` | `String` | Gets the image's ID. |
| `https://developers.google.com/apps-script/reference/document/positioned-image#getLayout()` | `https://developers.google.com/apps-script/reference/document/positioned-layout` | Gets an enum value that represents how the image is laid out. |
| `https://developers.google.com/apps-script/reference/document/positioned-image#getLeftOffset()` | `Number` | Gets the image's offset, in points, from the paragraph's left. |
| `https://developers.google.com/apps-script/reference/document/positioned-image#getParagraph()` | `https://developers.google.com/apps-script/reference/document/paragraph` | Gets the `https://developers.google.com/apps-script/reference/document/paragraph` the image is anchored to. |
| `https://developers.google.com/apps-script/reference/document/positioned-image#getTopOffset()` | `Number` | Gets the image's offset, in points, from the paragraph's top. |
| `https://developers.google.com/apps-script/reference/document/positioned-image#getWidth()` | `Integer` | Retrieves the image's width, in pixels. |
| `https://developers.google.com/apps-script/reference/document/positioned-image#setHeight(Integer)` | `https://developers.google.com/apps-script/reference/document/positioned-image#` | Sets the image's height, in pixels. |
| `https://developers.google.com/apps-script/reference/document/positioned-image#setLayout(PositionedLayout)` | `https://developers.google.com/apps-script/reference/document/positioned-image#` | Sets the definition of how the image is laid out. |
| `https://developers.google.com/apps-script/reference/document/positioned-image#setLeftOffset(Number)` | `https://developers.google.com/apps-script/reference/document/positioned-image#` | Sets the image's offset, in points, from the paragraph's left. |
| `https://developers.google.com/apps-script/reference/document/positioned-image#setTopOffset(Number)` | `https://developers.google.com/apps-script/reference/document/positioned-image#` | Sets the image's offset, in points, from the paragraph's top. |
| `https://developers.google.com/apps-script/reference/document/positioned-image#setWidth(Integer)` | `https://developers.google.com/apps-script/reference/document/positioned-image#` | Sets 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, "ShoppingList.12.25.2014" becomes
"ShoppingList.12.25.pdf".

To view the daily quotas for conversions, see [Quotas for Google
Services](https://developers.google.com/apps-script/guides/services/quotas). Newly created Google Workspace domains might be temporarily subject to stricter
quotas.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `contentType` | `String` | The 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. For a Google Docs document, `'text/markdown'` is also valid. |

#### Return


`https://developers.google.com/apps-script/reference/base/blob.html` --- The data as a blob.

*** ** * ** ***

### `getBlob()`

Return the data inside this object as a blob.

#### Return


`https://developers.google.com/apps-script/reference/base/blob.html` --- The data as a blob.

*** ** * ** ***

### `getHeight()`

Retrieves the image's height, in pixels.

#### Return


`Integer` --- the image's height, in pixels

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/documents.currentonly`
- `https://www.googleapis.com/auth/documents`

*** ** * ** ***

### `getId()`

Gets the image's ID.

#### Return


`String` --- the image ID

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/documents.currentonly`
- `https://www.googleapis.com/auth/documents`

*** ** * ** ***

### `getLayout()`

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

#### Return


`https://developers.google.com/apps-script/reference/document/positioned-layout` --- the image layout

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/documents.currentonly`
- `https://www.googleapis.com/auth/documents`

*** ** * ** ***

### `getLeftOffset()`

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

#### Return


`Number` --- the image offset from the left paragraph's left

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/documents.currentonly`
- `https://www.googleapis.com/auth/documents`

*** ** * ** ***

### `getParagraph()`

Gets the `https://developers.google.com/apps-script/reference/document/paragraph` the image is anchored to.

#### Return


`https://developers.google.com/apps-script/reference/document/paragraph` --- the parent paragraph

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/documents.currentonly`
- `https://www.googleapis.com/auth/documents`

*** ** * ** ***

### `getTopOffset()`

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

#### Return


`Number` --- the image offset from the left paragraph's top

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/documents.currentonly`
- `https://www.googleapis.com/auth/documents`

*** ** * ** ***

### `getWidth()`

Retrieves the image's width, in pixels.

#### Return


`Integer` --- the image's width, in pixels

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/documents.currentonly`
- `https://www.googleapis.com/auth/documents`

*** ** * ** ***

### `setHeight(height)`

Sets the image's height, in pixels.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `height` | `Integer` | the image's height, in pixels |

#### Return


`https://developers.google.com/apps-script/reference/document/positioned-image#` --- the current object

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/documents.currentonly`
- `https://www.googleapis.com/auth/documents`

*** ** * ** ***

### `setLayout(layout)`

Sets the definition of how the image is laid out.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `layout` | `https://developers.google.com/apps-script/reference/document/positioned-layout` | an enum representing the layout mode |

#### Return


`https://developers.google.com/apps-script/reference/document/positioned-image#` --- this object for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/documents.currentonly`
- `https://www.googleapis.com/auth/documents`

*** ** * ** ***

### `setLeftOffset(offset)`

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

#### Parameters

| Name | Type | Description |
|---|---|---|
| `offset` | `Number` | offset from the paragraph's left |

#### Return


`https://developers.google.com/apps-script/reference/document/positioned-image#` --- this object for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/documents.currentonly`
- `https://www.googleapis.com/auth/documents`

*** ** * ** ***

### `setTopOffset(offset)`

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

#### Parameters

| Name | Type | Description |
|---|---|---|
| `offset` | `Number` | offset from the paragraph's top |

#### Return


`https://developers.google.com/apps-script/reference/document/positioned-image#` --- this object for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/documents.currentonly`
- `https://www.googleapis.com/auth/documents`

*** ** * ** ***

### `setWidth(width)`

Sets the image's width, in pixels.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `width` | `Integer` | the image's width, in pixels |

#### Return


`https://developers.google.com/apps-script/reference/document/positioned-image#` --- the current object

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/documents.currentonly`
- `https://www.googleapis.com/auth/documents`