OneNote.Image class

Represents an Image. An Image can be a direct child of a PageContent object or a Paragraph object.

[ API set: OneNoteApi 1.1 ]

Extends
OfficeExtension.ClientObject

Properties

description

Gets or sets the description of the Image.

[ API set: OneNoteApi 1.1 ]

height

Gets or sets the height of the Image layout.

[ API set: OneNoteApi 1.1 ]

hyperlink

Gets or sets the hyperlink of the Image.

[ API set: OneNoteApi 1.1 ]

id

Gets the ID of the Image object. Read-only.

[ API set: OneNoteApi 1.1 ]

ocrData

Gets the data obtained by OCR (Optical Character Recognition) of this Image, such as OCR text and language.

[ API set: OneNoteApi 1.1 ]

pageContent

Gets the PageContent object that contains the Image. Throws if the Image is not a direct child of a PageContent. This object defines the position of the Image on the page. Read-only.

[ API set: OneNoteApi 1.1 ]

paragraph

Gets the Paragraph object that contains the Image. Throws if the Image is not a direct child of a Paragraph. Read-only.

[ API set: OneNoteApi 1.1 ]

width

Gets or sets the width of the Image layout.

[ API set: OneNoteApi 1.1 ]

Methods

getBase64Image()

Gets the base64-encoded binary representation of the Image. Example: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIA...

[ API set: OneNoteApi 1.1 ]

load(option)

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

toJSON()
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 are 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 needed to have added the object to the tracked object collection when the object was first created.

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 will need to call "context.sync()" before the memory release takes effect.

Property Details

description

Gets or sets the description of the Image.

[ API set: OneNoteApi 1.1 ]

description: string;
Property Value
string

height

Gets or sets the height of the Image layout.

[ API set: OneNoteApi 1.1 ]

height: number;
Property Value
number

Gets or sets the hyperlink of the Image.

[ API set: OneNoteApi 1.1 ]

hyperlink: string;
Property Value
string

id

Gets the ID of the Image object. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly id: string;
Property Value
string

ocrData

Gets the data obtained by OCR (Optical Character Recognition) of this Image, such as OCR text and language.

[ API set: OneNoteApi 1.1 ]

readonly ocrData: OneNote.ImageOcrData;
Property Value

pageContent

Gets the PageContent object that contains the Image. Throws if the Image is not a direct child of a PageContent. This object defines the position of the Image on the page. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly pageContent: OneNote.PageContent;
Property Value

paragraph

Gets the Paragraph object that contains the Image. Throws if the Image is not a direct child of a Paragraph. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly paragraph: OneNote.Paragraph;
Property Value

width

Gets or sets the width of the Image layout.

[ API set: OneNoteApi 1.1 ]

width: number;
Property Value
number

Method Details

getBase64Image()

Gets the base64-encoded binary representation of the Image. Example: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIA...

[ API set: OneNoteApi 1.1 ]

getBase64Image(): OfficeExtension.ClientResult<string>;
Returns
OfficeExtension.ClientResult<string>

Examples


var image = null;
var imageString;

OneNote.run(function(ctx){
    // Get the current outline.         
    var outline = ctx.application.getActiveOutline();

    // Queue a command to load paragraphs and their types. 
    outline.load("paragraphs/type")
    return ctx.sync().
        then(function(){
            for (var i=0; i < outline.paragraphs.items.length; i++)
            {
                var paragraph = outline.paragraphs.items[i];
                if (paragraph.type == "Image")
                {
                    image = paragraph.image;
                }
            }
        })
        .then(function(){
            if (image != null)
            {
                imageString = image.getBase64Image();
                return ctx.sync();
            }
        })
        .then(function(){
            console.log(imageString);
        });
});

load(option)

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

load(option?: string | string[]): OneNote.Image;
Parameters
option
string | string[]

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

Returns
Remarks

In addition to this signature, this method has the following signatures:

load(option?: { select?: string; expand?: string; }): OneNote.Image - Where option.select is a comma-delimited string that specifies the properties to load, and options.expand is a comma-delimited string that specifies the navigation properties to load.

load(option?: { select?: string; expand?: string; top?: number; skip?: number }): OneNote.Image - Only available on collection types. It is similar to the preceding signature. Option.top specifies the maximum number of collection items that can be included in the result. Option.skip specifies the number of items that are to be skipped and not included in the result. If option.top is specified, the result set will start after skipping the specified number of items.

Examples

OneNote.run(function(ctx){
    // Get the current outline.         
    var outline = ctx.application.getActiveOutline();
    var image = null;

    // Queue a command to load paragraphs and their types. 
    outline.load("paragraphs/type")
    return ctx.sync().
        then(function(){
            for (var i=0; i < outline.paragraphs.items.length; i++)
            {
                var paragraph = outline.paragraphs.items[i];
                if (paragraph.type == "Image")
                {
                    image = paragraph.image;
                }
            }
        })
        .then(function(){
            if (image != null)
            {
                // load every properties and relationships
                ctx.load(image);
                return ctx.sync();
            }
        })
        .then(function(){
            if (image != null)
            {                   
                console.log("image " + image.id + " width is " + image.width + " height is " + image.height);
                console.log("description: " + image.description);                   
                console.log("hyperlink: " + image.hyperlink);
            }
        });
});
var image = null;

OneNote.run(function(ctx){
    // Get the current outline.
    var outline = ctx.application.getActiveOutline();

    // Queue a command to load paragraphs and their types.
    outline.load("paragraphs")
    return ctx.sync().
        then(function(){
            for (var i=0; i < outline.paragraphs.items.length; i++)
            {
                var paragraph = outline.paragraphs.items[i];
                if (paragraph.type == "Image")
                {
                    image = paragraph.image;
                }
            }
            if (image != null)
            {
               image.load("ocrData");
            }
            return ctx.sync();
        })
        .then(function(){
            console.log(image.ocrData);
        });
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});
OneNote.run(function(ctx){
    // Get the current outline.         
    var outline = ctx.application.getActiveOutline();
    var searchedParagraph = null;

    // Queue a command to load paragraphs and their types. 
    outline.load("paragraphs/type")
    return ctx.sync().
        then(function() {
            for (var i=0; i < outline.paragraphs.items.length; i++)
            {
                var paragraph = outline.paragraphs.items[i];
                if (paragraph.type == "Image")
                {
                    searchedParagraph = paragraph;
                    break;
                }
            }
        })
        .then(function() {
            if (searchedParagraph != null)
            {
                // load every properties and relationships
                searchedParagraph.image.load('paragraph');
                return ctx.sync();
            }
        })
        .then(function() {
            if (searchedParagraph != null)
            {                   
                if (searchedParagraph.id != searchedParagraph.image.paragraph.id)
                {
                    console.log("id must match");
                }
            }
        });
})
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
}); 

toJSON()

toJSON(): OneNote.Interfaces.ImageData;
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 are 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 needed to have added the object to the tracked object collection when the object was first created.

track(): OneNote.Image;
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 will need to call "context.sync()" before the memory release takes effect.

untrack(): OneNote.Image;
Returns