Edit

Share via


Word.InlinePicture class

Represents an inline picture.

Extends

Remarks

[ API set: WordApi 1.1 ]

Examples

TypeScript
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/15-images/insert-and-get-pictures.yaml

// Inserts an image anchored to the last paragraph.
await Word.run(async (context) => {
  context.document.body.paragraphs
    .getLast()
    .insertParagraph("", "After")
    .insertInlinePictureFromBase64(base64Image, "End");

  await context.sync();
});

Properties

altTextDescription

Specifies a string that represents the alternative text associated with the inline image.

altTextTitle

Specifies a string that contains the title for the inline image.

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

height

Specifies a number that describes the height of the inline image.

hyperlink

Specifies a hyperlink on the image. Use a '#' to separate the address part from the optional location part.

lockAspectRatio

Specifies a value that indicates whether the inline image retains its original proportions when you resize it.

paragraph

Gets the parent paragraph that contains the inline image.

parentContentControl

Gets the content control that contains the inline image. Throws an ItemNotFound error if there isn't a parent content control.

parentContentControlOrNullObject

Gets the content control that contains the inline image. If there isn't a parent content control, then this method will return an object with its isNullObject property set to true. For further information, see *OrNullObject methods and properties.

parentTable

Gets the table that contains the inline image. Throws an ItemNotFound error if it isn't contained in a table.

parentTableCell

Gets the table cell that contains the inline image. Throws an ItemNotFound error if it isn't contained in a table cell.

parentTableCellOrNullObject

Gets the table cell that contains the inline image. If it isn't contained in a table cell, then this method will return an object with its isNullObject property set to true. For further information, see *OrNullObject methods and properties.

parentTableOrNullObject

Gets the table that contains the inline image. If it isn't contained in a table, then this method will return an object with its isNullObject property set to true. For further information, see *OrNullObject methods and properties.

width

Specifies a number that describes the width of the inline image.

Methods

delete()

Deletes the inline picture from the document.

getBase64ImageSrc()

Gets the Base64-encoded string representation of the inline image.

getNext()

Gets the next inline image. Throws an ItemNotFound error if this inline image is the last one.

getNextOrNullObject()

Gets the next inline image. If this inline image is the last one, then this method will return an object with its isNullObject property set to true. For further information, see *OrNullObject methods and properties.

getRange(rangeLocation)

Gets the picture, or the starting or ending point of the picture, as a range.

insertBreak(breakType, insertLocation)

Inserts a break at the specified location in the main document.

insertContentControl()

Wraps the inline picture with a rich text content control.

insertFileFromBase64(base64File, insertLocation)

Inserts a document at the specified location.

insertHtml(html, insertLocation)

Inserts HTML at the specified location.

insertInlinePictureFromBase64(base64EncodedImage, insertLocation)

Inserts an inline picture at the specified location.

insertOoxml(ooxml, insertLocation)

Inserts OOXML at the specified location.

insertParagraph(paragraphText, insertLocation)

Inserts a paragraph at the specified location.

insertText(text, insertLocation)

Inserts text at the specified location.

load(options)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

select(selectionMode)

Selects the inline picture. This causes Word to scroll to the selection.

select(selectionModeString)

Selects the inline picture. This causes Word to scroll to the selection.

set(properties, options)

Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type.

set(properties)

Sets multiple properties on the object at the same time, based on an existing loaded object.

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that's passed to it.) Whereas the original Word.InlinePicture object is an API object, the toJSON method returns a plain JavaScript object (typed as Word.Interfaces.InlinePictureData) that contains shallow copies of any loaded child properties from the original object.

track()

Track the object for automatic adjustment based on surrounding changes in the document. This call is a shorthand for context.trackedObjects.add(thisObject). If you're using this object across .sync calls and outside the sequential execution of a ".run" batch, and get an "InvalidObjectPath" error when setting a property or invoking a method on the object, you need to add the object to the tracked object collection when the object was first created. If this object is part of a collection, you should also track the parent collection.

untrack()

Release the memory associated with this object, if it has previously been tracked. This call is shorthand for context.trackedObjects.remove(thisObject). Having many tracked objects slows down the host application, so please remember to free any objects you add, once you're done using them. You'll need to call context.sync() before the memory release takes effect.

Property Details

altTextDescription

Specifies a string that represents the alternative text associated with the inline image.

TypeScript
altTextDescription: string;

Property Value

string

Remarks

[ API set: WordApi 1.1 ]

altTextTitle

Specifies a string that contains the title for the inline image.

TypeScript
altTextTitle: string;

Property Value

string

Remarks

[ API set: WordApi 1.1 ]

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

TypeScript
context: RequestContext;

Property Value

height

Specifies a number that describes the height of the inline image.

TypeScript
height: number;

Property Value

number

Remarks

[ API set: WordApi 1.1 ]

Specifies a hyperlink on the image. Use a '#' to separate the address part from the optional location part.

TypeScript
hyperlink: string;

Property Value

string

Remarks

[ API set: WordApi 1.1 ]

lockAspectRatio

Specifies a value that indicates whether the inline image retains its original proportions when you resize it.

TypeScript
lockAspectRatio: boolean;

Property Value

boolean

Remarks

[ API set: WordApi 1.1 ]

paragraph

Gets the parent paragraph that contains the inline image.

TypeScript
readonly paragraph: Word.Paragraph;

Property Value

Remarks

[ API set: WordApi 1.2 ]

parentContentControl

Gets the content control that contains the inline image. Throws an ItemNotFound error if there isn't a parent content control.

TypeScript
readonly parentContentControl: Word.ContentControl;

Property Value

Remarks

[ API set: WordApi 1.1 ]

parentContentControlOrNullObject

Gets the content control that contains the inline image. If there isn't a parent content control, then this method will return an object with its isNullObject property set to true. For further information, see *OrNullObject methods and properties.

TypeScript
readonly parentContentControlOrNullObject: Word.ContentControl;

Property Value

Remarks

[ API set: WordApi 1.3 ]

parentTable

Gets the table that contains the inline image. Throws an ItemNotFound error if it isn't contained in a table.

TypeScript
readonly parentTable: Word.Table;

Property Value

Remarks

[ API set: WordApi 1.3 ]

parentTableCell

Gets the table cell that contains the inline image. Throws an ItemNotFound error if it isn't contained in a table cell.

TypeScript
readonly parentTableCell: Word.TableCell;

Property Value

Remarks

[ API set: WordApi 1.3 ]

parentTableCellOrNullObject

Gets the table cell that contains the inline image. If it isn't contained in a table cell, then this method will return an object with its isNullObject property set to true. For further information, see *OrNullObject methods and properties.

TypeScript
readonly parentTableCellOrNullObject: Word.TableCell;

Property Value

Remarks

[ API set: WordApi 1.3 ]

parentTableOrNullObject

Gets the table that contains the inline image. If it isn't contained in a table, then this method will return an object with its isNullObject property set to true. For further information, see *OrNullObject methods and properties.

TypeScript
readonly parentTableOrNullObject: Word.Table;

Property Value

Remarks

[ API set: WordApi 1.3 ]

width

Specifies a number that describes the width of the inline image.

TypeScript
width: number;

Property Value

number

Remarks

[ API set: WordApi 1.1 ]

Method Details

delete()

Deletes the inline picture from the document.

TypeScript
delete(): void;

Returns

void

Remarks

[ API set: WordApi 1.2 ]

getBase64ImageSrc()

Gets the Base64-encoded string representation of the inline image.

TypeScript
getBase64ImageSrc(): OfficeExtension.ClientResult<string>;

Returns

Remarks

[ API set: WordApi 1.1 ]

Examples

TypeScript
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/15-images/insert-and-get-pictures.yaml

// Gets the first image in the document.
await Word.run(async (context) => {
  const firstPicture: Word.InlinePicture = context.document.body.inlinePictures.getFirst();
  firstPicture.load("width, height, imageFormat");

  await context.sync();
  console.log(`Image dimensions: ${firstPicture.width} x ${firstPicture.height}`, `Image format: ${firstPicture.imageFormat}`);
  // Get the image encoded as Base64.
  const base64 = firstPicture.getBase64ImageSrc();

  await context.sync();
  console.log(base64.value);
});

getNext()

Gets the next inline image. Throws an ItemNotFound error if this inline image is the last one.

TypeScript
getNext(): Word.InlinePicture;

Returns

Remarks

[ API set: WordApi 1.3 ]

Examples

TypeScript
// To use this snippet, add an inline picture to the document and assign it an alt text title.
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
    
    // Create a proxy object for the first inline picture.
    const firstPicture = context.document.body.inlinePictures.getFirstOrNullObject();

    // Queue a command to load the alternative text title of the picture.
    firstPicture.load('altTextTitle');

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();
    if (firstPicture.isNullObject) {
        console.log('There are no inline pictures in this document.')
    } else {
        console.log(firstPicture.altTextTitle);
    }
}); 

getNextOrNullObject()

Gets the next inline image. If this inline image is the last one, then this method will return an object with its isNullObject property set to true. For further information, see *OrNullObject methods and properties.

TypeScript
getNextOrNullObject(): Word.InlinePicture;

Returns

Remarks

[ API set: WordApi 1.3 ]

Examples

TypeScript
// To use this snippet, add an inline picture to the document and assign it an alt text title.
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
    
    // Create a proxy object for the first inline picture.
    const firstPicture = context.document.body.inlinePictures.getFirstOrNullObject();

    // Queue a command to load the alternative text title of the picture.
    firstPicture.load('altTextTitle');

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();
    if (firstPicture.isNullObject) {
        console.log('There are no inline pictures in this document.')
    } else {
        console.log(firstPicture.altTextTitle);
    }
}); 

getRange(rangeLocation)

Gets the picture, or the starting or ending point of the picture, as a range.

TypeScript
getRange(rangeLocation?: Word.RangeLocation.whole | Word.RangeLocation.start | Word.RangeLocation.end | "Whole" | "Start" | "End"): Word.Range;

Parameters

rangeLocation

whole | start | end | "Whole" | "Start" | "End"

Optional. The range location must be 'Whole', 'Start', or 'End'.

Returns

Remarks

[ API set: WordApi 1.3 ]

insertBreak(breakType, insertLocation)

Inserts a break at the specified location in the main document.

TypeScript
insertBreak(breakType: Word.BreakType | "Page" | "Next" | "SectionNext" | "SectionContinuous" | "SectionEven" | "SectionOdd" | "Line", insertLocation: Word.InsertLocation.before | Word.InsertLocation.after | "Before" | "After"): void;

Parameters

breakType

Word.BreakType | "Page" | "Next" | "SectionNext" | "SectionContinuous" | "SectionEven" | "SectionOdd" | "Line"

Required. The break type to add.

insertLocation

before | after | "Before" | "After"

Required. The value must be 'Before' or 'After'.

Returns

void

Remarks

[ API set: WordApi 1.2 ]

insertContentControl()

Wraps the inline picture with a rich text content control.

TypeScript
insertContentControl(): Word.ContentControl;

Returns

Remarks

[ API set: WordApi 1.1 ]

insertFileFromBase64(base64File, insertLocation)

Inserts a document at the specified location.

TypeScript
insertFileFromBase64(base64File: string, insertLocation: Word.InsertLocation.before | Word.InsertLocation.after | "Before" | "After"): Word.Range;

Parameters

base64File

string

Required. The Base64-encoded content of a .docx file.

insertLocation

before | after | "Before" | "After"

Required. The value must be 'Before' or 'After'.

Returns

Remarks

[ API set: WordApi 1.2 ]

Note: Insertion isn't supported if the document being inserted contains an ActiveX control (likely in a form field). Consider replacing such a form field with a content control or other option appropriate for your scenario.

insertHtml(html, insertLocation)

Inserts HTML at the specified location.

TypeScript
insertHtml(html: string, insertLocation: Word.InsertLocation.before | Word.InsertLocation.after | "Before" | "After"): Word.Range;

Parameters

html

string

Required. The HTML to be inserted.

insertLocation

before | after | "Before" | "After"

Required. The value must be 'Before' or 'After'.

Returns

Remarks

[ API set: WordApi 1.2 ]

insertInlinePictureFromBase64(base64EncodedImage, insertLocation)

Inserts an inline picture at the specified location.

TypeScript
insertInlinePictureFromBase64(base64EncodedImage: string, insertLocation: Word.InsertLocation.replace | Word.InsertLocation.before | Word.InsertLocation.after | "Replace" | "Before" | "After"): Word.InlinePicture;

Parameters

base64EncodedImage

string

Required. The Base64-encoded image to be inserted.

insertLocation

replace | before | after | "Replace" | "Before" | "After"

Required. The value must be 'Replace', 'Before', or 'After'.

Returns

Remarks

[ API set: WordApi 1.2 ]

insertOoxml(ooxml, insertLocation)

Inserts OOXML at the specified location.

TypeScript
insertOoxml(ooxml: string, insertLocation: Word.InsertLocation.before | Word.InsertLocation.after | "Before" | "After"): Word.Range;

Parameters

ooxml

string

Required. The OOXML to be inserted.

insertLocation

before | after | "Before" | "After"

Required. The value must be 'Before' or 'After'.

Returns

Remarks

[ API set: WordApi 1.2 ]

insertParagraph(paragraphText, insertLocation)

Inserts a paragraph at the specified location.

TypeScript
insertParagraph(paragraphText: string, insertLocation: Word.InsertLocation.before | Word.InsertLocation.after | "Before" | "After"): Word.Paragraph;

Parameters

paragraphText

string

Required. The paragraph text to be inserted.

insertLocation

before | after | "Before" | "After"

Required. The value must be 'Before' or 'After'.

Returns

Remarks

[ API set: WordApi 1.2 ]

insertText(text, insertLocation)

Inserts text at the specified location.

TypeScript
insertText(text: string, insertLocation: Word.InsertLocation.before | Word.InsertLocation.after | "Before" | "After"): Word.Range;

Parameters

text

string

Required. Text to be inserted.

insertLocation

before | after | "Before" | "After"

Required. The value must be 'Before' or 'After'.

Returns

Remarks

[ API set: WordApi 1.2 ]

load(options)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

TypeScript
load(options?: Word.Interfaces.InlinePictureLoadOptions): Word.InlinePicture;

Parameters

options
Word.Interfaces.InlinePictureLoadOptions

Provides options for which properties of the object to load.

Returns

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

TypeScript
load(propertyNames?: string | string[]): Word.InlinePicture;

Parameters

propertyNames

string | string[]

A comma-delimited string or an array of strings that specify the properties to load.

Returns

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

TypeScript
load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): Word.InlinePicture;

Parameters

propertyNamesAndPaths

{ select?: string; expand?: string; }

propertyNamesAndPaths.select is a comma-delimited string that specifies the properties to load, and propertyNamesAndPaths.expand is a comma-delimited string that specifies the navigation properties to load.

Returns

select(selectionMode)

Selects the inline picture. This causes Word to scroll to the selection.

TypeScript
select(selectionMode?: Word.SelectionMode): void;

Parameters

selectionMode
Word.SelectionMode

Optional. The selection mode must be 'Select', 'Start', or 'End'. 'Select' is the default.

Returns

void

Remarks

[ API set: WordApi 1.2 ]

select(selectionModeString)

Selects the inline picture. This causes Word to scroll to the selection.

TypeScript
select(selectionModeString?: "Select" | "Start" | "End"): void;

Parameters

selectionModeString

"Select" | "Start" | "End"

Optional. The selection mode must be 'Select', 'Start', or 'End'. 'Select' is the default.

Returns

void

Remarks

[ API set: WordApi 1.2 ]

set(properties, options)

Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type.

TypeScript
set(properties: Interfaces.InlinePictureUpdateData, options?: OfficeExtension.UpdateOptions): void;

Parameters

properties
Word.Interfaces.InlinePictureUpdateData

A JavaScript object with properties that are structured isomorphically to the properties of the object on which the method is called.

options
OfficeExtension.UpdateOptions

Provides an option to suppress errors if the properties object tries to set any read-only properties.

Returns

void

set(properties)

Sets multiple properties on the object at the same time, based on an existing loaded object.

TypeScript
set(properties: Word.InlinePicture): void;

Parameters

properties
Word.InlinePicture

Returns

void

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that's passed to it.) Whereas the original Word.InlinePicture object is an API object, the toJSON method returns a plain JavaScript object (typed as Word.Interfaces.InlinePictureData) that contains shallow copies of any loaded child properties from the original object.

TypeScript
toJSON(): Word.Interfaces.InlinePictureData;

Returns

track()

Track the object for automatic adjustment based on surrounding changes in the document. This call is a shorthand for context.trackedObjects.add(thisObject). If you're using this object across .sync calls and outside the sequential execution of a ".run" batch, and get an "InvalidObjectPath" error when setting a property or invoking a method on the object, you need to add the object to the tracked object collection when the object was first created. If this object is part of a collection, you should also track the parent collection.

TypeScript
track(): Word.InlinePicture;

Returns

untrack()

Release the memory associated with this object, if it has previously been tracked. This call is shorthand for context.trackedObjects.remove(thisObject). Having many tracked objects slows down the host application, so please remember to free any objects you add, once you're done using them. You'll need to call context.sync() before the memory release takes effect.

TypeScript
untrack(): Word.InlinePicture;

Returns