InlinePicture Object (JavaScript API for Word)

Word 2016, Word for iPad, Word for Mac, Word Online

Represents an inline picture.

Properties

Property Type Description Req. Set
altTextDescription string Gets or sets a string that represents the alternative text associated with the inline image 1.1
altTextTitle string Gets or sets a string that contains the title for the inline image. 1.1
height float Gets or sets a number that describes the height of the inline image. 1.1
hyperlink string Gets or sets a hyperlink on the image. Use a '#' to separate the address part from the optional location part. 1.1
lockAspectRatio bool Gets or sets a value that indicates whether the inline image retains its original proportions when you resize it. 1.1
width float Gets or sets a number that describes the width of the inline image. 1.1

Relationships

Relationship Type Description Req. Set
paragraph Paragraph Gets the parent paragraph that contains the inline image. Read-only. 1.2
parentContentControl ContentControl Gets the content control that contains the inline image. Throws if there isn't a parent content control. Read-only. 1.1
parentContentControlOrNullObject ContentControl Gets the content control that contains the inline image. Returns a null object if there isn't a parent content control. Read-only. 1.3
parentTable Table Gets the table that contains the inline image. Throws if it is not contained in a table. Read-only. 1.3
parentTableCell TableCell Gets the table cell that contains the inline image. Throws if it is not contained in a table cell. Read-only. 1.3
parentTableCellOrNullObject TableCell Gets the table cell that contains the inline image. Returns a null object if it is not contained in a table cell. Read-only. 1.3
parentTableOrNullObject Table Gets the table that contains the inline image. Returns a null object if it is not contained in a table. Read-only. 1.3

Methods

Method Return Type Description Req. Set
delete() void Deletes the inline picture from the document. 1.2
getBase64ImageSrc() string Gets the base64 encoded string representation of the inline image. 1.1
getNext() InlinePicture Gets the next inline image. Throws if this inline image is the last one. 1.3
getNextOrNullObject() InlinePicture Gets the next inline image. Returns a null object if this inline image is the last one. 1.3
getRange(rangeLocation: string) Range Gets the picture, or the starting or ending point of the picture, as a range. 1.3
insertBreak(breakType: string, insertLocation: string) void Inserts a break at the specified location in the main document. The insertLocation value can be 'Before' or 'After'. 1.2
insertContentControl() ContentControl Wraps the inline picture with a rich text content control. 1.1
insertFileFromBase64(base64File: string, insertLocation: string) Range Inserts a document at the specified location. The insertLocation value can be 'Before' or 'After'. 1.2
insertHtml(html: string, insertLocation: string) Range Inserts HTML at the specified location. The insertLocation value can be 'Before' or 'After'. 1.2
insertInlinePictureFromBase64(base64EncodedImage: string, insertLocation: string) InlinePicture Inserts an inline picture at the specified location. The insertLocation value can be 'Replace', 'Before' or 'After'. 1.2
insertOoxml(ooxml: string, insertLocation: string) Range Inserts OOXML at the specified location. The insertLocation value can be 'Before' or 'After'. 1.2
insertParagraph(paragraphText: string, insertLocation: string) Paragraph Inserts a paragraph at the specified location. The insertLocation value can be 'Before' or 'After'. 1.2
insertText(text: string, insertLocation: string) Range Inserts text at the specified location. The insertLocation value can be 'Before' or 'After'. 1.2
load(param: object) void Fills the proxy object created in JavaScript layer with property and object values specified in the parameter. 1.1
select(selectionMode: string) void Selects the inline picture. This causes Word to scroll to the selection. 1.2

Method Details

delete()

Deletes the inline picture from the document.

Syntax

inlinePictureObject.delete();

Parameters

None

Returns

void

getBase64ImageSrc()

Gets the base64 encoded string representation of the inline image.

Syntax

inlinePictureObject.getBase64ImageSrc();

Parameters

None

Returns

string

getNext()

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

Syntax

inlinePictureObject.getNext();

Parameters

None

Returns

InlinePicture

Examples

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.
Word.run(function (context) {
    
    // Create a proxy object for the first inline picture.
    var firstPicture = context.document.body.inlinePictures.getFirstOrNullObject();

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

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    return context.sync().then(function () {
        if (firstPicture.isNullObject) {
            console.log('There are inline pictures in this document.')
        } else {
            console.log(firstPicture.altTextTitle);
        }
    });   
})
.catch(function (error) {
    console.log('Error: ' + JSON.stringify(error));
    if (error instanceof OfficeExtension.Error) {
        console.log('Debug info: ' + JSON.stringify(error.debugInfo));
    }
});

getNextOrNullObject()

Gets the next inline image. Returns a null object if this inline image is the last one.

Syntax

inlinePictureObject.getNextOrNullObject();

Parameters

None

Returns

InlinePicture

Examples

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.
Word.run(function (context) {
    
    // Create a proxy object for the first inline picture.
    var firstPicture = context.document.body.inlinePictures.getFirstOrNullObject();

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

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    return context.sync().then(function () {
        if (firstPicture.isNullObject) {
            console.log('There are inline pictures in this document.')
        } else {
            console.log(firstPicture.altTextTitle);
        }
    });   
})
.catch(function (error) {
    console.log('Error: ' + JSON.stringify(error));
    if (error instanceof OfficeExtension.Error) {
        console.log('Debug info: ' + JSON.stringify(error.debugInfo));
    }
});

getRange(rangeLocation: string)

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

Syntax

inlinePictureObject.getRange(rangeLocation);

Parameters

Parameter Type Description
rangeLocation string Optional. Optional. The range location can be 'Whole', 'Start' or 'End'. Possible values are: Whole, Start, End, Before, After, Content

Returns

Range

insertBreak(breakType: string, insertLocation: string)

Inserts a break at the specified location in the main document. The insertLocation value can be 'Before' or 'After'.

Syntax

inlinePictureObject.insertBreak(breakType, insertLocation);

Parameters

Parameter Type Description
breakType string Required. The break type to add. Possible values are: Page Page break at the insertion point.,Column Column break at the insertion point.,Next Section break on next page.,SectionContinuous New section without a corresponding page break.,SectionEven Section break with the next section beginning on the next even-numbered page. If the section break falls on an even-numbered page, Word leaves the next odd-numbered page blank.,SectionOdd Section break with the next section beginning on the next odd-numbered page. If the section break falls on an odd-numbered page, Word leaves the next even-numbered page blank.,Line Line break.,LineClearLeft Line break.,LineClearRight Line break.,TextWrapping Ends the current line and forces the text to continue below a picture, table, or other item. The text continues on the next blank line that does not contain a table aligned with the left or right margin.
insertLocation string Required. The value can be 'Before' or 'After'. Possible values are: Before Add content before the contents of the calling object.,After Add content after the contents of the calling object.,Start Prepend content to the contents of the calling object.,End Append content to the contents of the calling object.,Replace Replace the contents of the current object.

Returns

void

insertContentControl()

Wraps the inline picture with a rich text content control.

Syntax

inlinePictureObject.insertContentControl();

Parameters

None

Returns

ContentControl

insertFileFromBase64(base64File: string, insertLocation: string)

Inserts a document at the specified location. The insertLocation value can be 'Before' or 'After'.

Syntax

inlinePictureObject.insertFileFromBase64(base64File, insertLocation);

Parameters

Parameter Type Description
base64File string Required. The base64 encoded content of a .docx file.
insertLocation string Required. The value can be 'Before' or 'After'. Possible values are: Before Add content before the contents of the calling object.,After Add content after the contents of the calling object.,Start Prepend content to the contents of the calling object.,End Append content to the contents of the calling object.,Replace Replace the contents of the current object.

Returns

Range

insertHtml(html: string, insertLocation: string)

Inserts HTML at the specified location. The insertLocation value can be 'Before' or 'After'.

Syntax

inlinePictureObject.insertHtml(html, insertLocation);

Parameters

Parameter Type Description
html string Required. The HTML to be inserted.
insertLocation string Required. The value can be 'Before' or 'After'. Possible values are: Before Add content before the contents of the calling object.,After Add content after the contents of the calling object.,Start Prepend content to the contents of the calling object.,End Append content to the contents of the calling object.,Replace Replace the contents of the current object.

Returns

Range

insertInlinePictureFromBase64(base64EncodedImage: string, insertLocation: string)

Inserts an inline picture at the specified location. The insertLocation value can be 'Replace', 'Before' or 'After'.

Syntax

inlinePictureObject.insertInlinePictureFromBase64(base64EncodedImage, insertLocation);

Parameters

Parameter Type Description
base64EncodedImage string Required. The base64 encoded image to be inserted.
insertLocation string Required. The value can be 'Replace', 'Before' or 'After'. Possible values are: Before Add content before the contents of the calling object.,After Add content after the contents of the calling object.,Start Prepend content to the contents of the calling object.,End Append content to the contents of the calling object.,Replace Replace the contents of the current object.

Returns

InlinePicture

insertOoxml(ooxml: string, insertLocation: string)

Inserts OOXML at the specified location. The insertLocation value can be 'Before' or 'After'.

Syntax

inlinePictureObject.insertOoxml(ooxml, insertLocation);

Parameters

Parameter Type Description
ooxml string Required. The OOXML to be inserted.
insertLocation string Required. The value can be 'Before' or 'After'. Possible values are: Before Add content before the contents of the calling object.,After Add content after the contents of the calling object.,Start Prepend content to the contents of the calling object.,End Append content to the contents of the calling object.,Replace Replace the contents of the current object.

Returns

Range

insertParagraph(paragraphText: string, insertLocation: string)

Inserts a paragraph at the specified location. The insertLocation value can be 'Before' or 'After'.

Syntax

inlinePictureObject.insertParagraph(paragraphText, insertLocation);

Parameters

Parameter Type Description
paragraphText string Required. The paragraph text to be inserted.
insertLocation string Required. The value can be 'Before' or 'After'. Possible values are: Before Add content before the contents of the calling object.,After Add content after the contents of the calling object.,Start Prepend content to the contents of the calling object.,End Append content to the contents of the calling object.,Replace Replace the contents of the current object.

Returns

Paragraph

insertText(text: string, insertLocation: string)

Inserts text at the specified location. The insertLocation value can be 'Before' or 'After'.

Syntax

inlinePictureObject.insertText(text, insertLocation);

Parameters

Parameter Type Description
text string Required. Text to be inserted.
insertLocation string Required. The value can be 'Before' or 'After'. Possible values are: Before Add content before the contents of the calling object.,After Add content after the contents of the calling object.,Start Prepend content to the contents of the calling object.,End Append content to the contents of the calling object.,Replace Replace the contents of the current object.

Returns

Range

load(param: object)

Fills the proxy object created in JavaScript layer with property and object values specified in the parameter.

Syntax

object.load(param);

Parameters

Parameter Type Description
param object Optional. Accepts parameter and relationship names as delimited string or an array. Or, provide loadOption object.

Returns

void

select(selectionMode: string)

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

Syntax

inlinePictureObject.select(selectionMode);

Parameters

Parameter Type Description
selectionMode string Optional. Optional. The selection mode can be 'Select', 'Start' or 'End'. 'Select' is the default. Possible values are: Select, Start, End

Returns

void