OneNote.Page class

Represents a OneNote page.

[ API set: OneNoteApi 1.1 ]

Extends
OfficeExtension.ClientObject

Properties

classNotebookPageSource

Gets the ClassNotebookPageSource to the page.

[ API set: OneNoteApi 1.1 ]

clientUrl

The client url of the page. Read only

[ API set: OneNoteApi 1.1 ]

contents

The collection of PageContent objects on the page. Read only

[ API set: OneNoteApi 1.1 ]

id

Gets the ID of the page. Read-only.

[ API set: OneNoteApi 1.1 ]

inkAnalysisOrNull

Text interpretation for the ink on the page. Returns null if there is no ink analysis information. Read only.

[ API set: OneNoteApi 1.1 ]

pageLevel

Gets or sets the indentation level of the page.

[ API set: OneNoteApi 1.1 ]

parentSection

Gets the section that contains the page. Read-only.

[ API set: OneNoteApi 1.1 ]

title

Gets or sets the title of the page.

[ API set: OneNoteApi 1.1 ]

webUrl

The web url of the page. Read only

[ API set: OneNoteApi 1.1 ]

Methods

addOutline(left, top, html)

Adds an Outline to the page at the specified position.

[ API set: OneNoteApi 1.1 ]

analyzePage()

Return a json string with node id and content in html format.

[ API set: OneNoteApi 1.1 ]

applyTranslation(translatedContent)

Inserts a new page with translated content.

[ API set: OneNoteApi 1.1 ]

copyToSection(destinationSection)

Copies this page to specified section.

[ API set: OneNoteApi 1.1 ]

copyToSectionAndSetClassNotebookPageSource(destinationSection)

Copies this page to specified section and sets ClassNotebookPageSource.

[ API set: OneNoteApi 1.1 ]

getRestApiId()

Gets the REST API ID.

[ API set: OneNoteApi 1.1 ]

hasTitleContent()

Does the page has content title.

[ API set: OneNoteApi 1.1 ]

insertPageAsSibling(location, title)

Inserts a new page before or after the current page.

[ 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

classNotebookPageSource

Gets the ClassNotebookPageSource to the page.

[ API set: OneNoteApi 1.1 ]

readonly classNotebookPageSource: string;
Property Value
string

clientUrl

The client url of the page. Read only

[ API set: OneNoteApi 1.1 ]

readonly clientUrl: string;
Property Value
string

contents

The collection of PageContent objects on the page. Read only

[ API set: OneNoteApi 1.1 ]

readonly contents: OneNote.PageContentCollection;
Property Value

id

Gets the ID of the page. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly id: string;
Property Value
string

inkAnalysisOrNull

Text interpretation for the ink on the page. Returns null if there is no ink analysis information. Read only.

[ API set: OneNoteApi 1.1 ]

readonly inkAnalysisOrNull: OneNote.InkAnalysis;
Property Value

pageLevel

Gets or sets the indentation level of the page.

[ API set: OneNoteApi 1.1 ]

pageLevel: number;
Property Value
number

parentSection

Gets the section that contains the page. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly parentSection: OneNote.Section;
Property Value

title

Gets or sets the title of the page.

[ API set: OneNoteApi 1.1 ]

title: string;
Property Value
string

webUrl

The web url of the page. Read only

[ API set: OneNoteApi 1.1 ]

readonly webUrl: string;
Property Value
string

Method Details

addOutline(left, top, html)

Adds an Outline to the page at the specified position.

[ API set: OneNoteApi 1.1 ]

addOutline(left: number, top: number, html: string): OneNote.Outline;
Parameters
left
number

The left position of the top, left corner of the Outline.

top
number

The top position of the top, left corner of the Outline.

html
string

An HTML string that describes the visual presentation of the Outline. See Supported HTML for the OneNote add-ins JavaScript API.

Returns

Examples

OneNote.run(function (context) {

    // Gets the active page.
    var page = context.application.getActivePage();

    // Queue a command to add an outline with given html. 
    var outline = page.addOutline(200, 200,
"<p>Images and a table below:</p> \
 <img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==\"> \
 <img src=\"http://imagenes.es.sftcdn.net/es/scrn/6653000/6653659/microsoft-onenote-2013-01-535x535.png\"> \
 <table> \
   <tr> \
     <td>Jill</td> \
     <td>Smith</td> \
     <td>50</td> \
   </tr> \
   <tr> \
     <td>Eve</td> \
     <td>Jackson</td> \
     <td>94</td> \
   </tr> \
 </table>"     
        );

    // Run the queued commands, and return a promise to indicate task completion.
    return context.sync()
        .catch(function(error) {
            console.log("Error: " + error);
            if (error instanceof OfficeExtension.Error) {
                console.log("Debug info: " + JSON.stringify(error.debugInfo));
            }
        });
});

analyzePage()

Return a json string with node id and content in html format.

[ API set: OneNoteApi 1.1 ]

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

applyTranslation(translatedContent)

Inserts a new page with translated content.

[ API set: OneNoteApi 1.1 ]

applyTranslation(translatedContent: string): void;
Parameters
translatedContent
string

Translated content of the page

Returns
void

copyToSection(destinationSection)

Copies this page to specified section.

[ API set: OneNoteApi 1.1 ]

copyToSection(destinationSection: OneNote.Section): OneNote.Page;
Parameters
destinationSection
OneNote.Section

The section to copy this page to.

Returns

Examples

OneNote.run(function(ctx) {
    var app = ctx.application;

    // Gets the active notebook.
    var notebook = app.getActiveNotebook();

    // Gets the active page.
    var page = app.getActivePage();

    // Queue a command to load sections under the notebook.
    notebook.load('sections');

    var newPage;

    // Run the queued commands, and return a promise to indicate task completion.
    return ctx.sync()
        .then(function() {
            var section = notebook.sections.items[0];

            // copy page to the section.
            newPage = page.copyToSection(section);
            newPage.load('id');
            return ctx.sync();
        })
        .then(function() {
            console.log(newPage.id);
        });
})
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

copyToSectionAndSetClassNotebookPageSource(destinationSection)

Copies this page to specified section and sets ClassNotebookPageSource.

[ API set: OneNoteApi 1.1 ]

copyToSectionAndSetClassNotebookPageSource(destinationSection: OneNote.Section): OneNote.Page;
Parameters
destinationSection
OneNote.Section
Returns

getRestApiId()

Gets the REST API ID.

[ API set: OneNoteApi 1.1 ]

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

Examples

OneNote.run(function(ctx){
    // Get the current page.         
    var page = ctx.application.getActivePage();
    var restApiId = page.getRestApiId();

    return ctx.sync().
        then(function(){
            console.log("The REST API ID is " + restApiId.value);
            // Note that the REST API ID isn't all you need to interact with the OneNote REST API.
            // This is only required for SharePoint notebooks. baseUrl will be null for OneDrive notebooks.
            // For SharePoint notebooks, the notebook baseUrl should be used to talk to the OneNote REST API
            // according to the OneNote Development Blog.
            // https://blogs.msdn.microsoft.com/onenotedev/2015/06/11/and-sharepoint-makes-three/
        });
});

hasTitleContent()

Does the page has content title.

[ API set: OneNoteApi 1.1 ]

hasTitleContent(): OfficeExtension.ClientResult<boolean>;
Returns
OfficeExtension.ClientResult<boolean>

insertPageAsSibling(location, title)

Inserts a new page before or after the current page.

[ API set: OneNoteApi 1.1 ]

insertPageAsSibling(location: OneNote.InsertLocation, title: string): OneNote.Page;
Parameters
location
OneNote.InsertLocation

The location of the new page relative to the current page.

title
string

The title of the new page.

Returns

Examples

OneNote.run(function (context) {

    // Gets the active page.
    var activePage = context.application.getActivePage();

    // Queue a command to add a new page after the active page. 
    var newPage = activePage.insertPageAsSibling("After", "Next Page");

    // Queue a command to load the newPage to access its data.
    context.load(newPage);

    // Run the queued commands, and return a promise to indicate task completion.
    return context.sync()
        .then(function() {
            console.log("page is created with title: " + newPage.title);
        });
})
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

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.Page;
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.Page - 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.Page - 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 (context) {

    // Gets the active page.
    var activePage = context.application.getActivePage();

    // Queue a command to add a new page after the active page. 
    var pageContents = activePage.contents;

    // Queue a command to load the pageContents to access its data.
    context.load(pageContents);

    // Run the queued commands, and return a promise to indicate task completion.
    return context.sync()
        .then(function() {
            for(var i=0; i < pageContents.items.length; i++)
            {
                var pageContent = pageContents.items[i];
                if (pageContent.type == "Outline")
                {
                    console.log("Found an outline");
                }
                else if (pageContent.type == "Image")
                {
                    console.log("Found an image");
                }
                else if (pageContent.type == "Other")
                {
                    console.log("Found a type not supported yet.");
                }
            }
        });
})
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});
OneNote.run(function (context) {

    var app = context.application;

    // Gets the active page.
    var page = app.getActivePage();

    // Queue a command to load the webUrl of the page.
    page.load("webUrl");

    // Run the queued commands, and return a promise to indicate task completion.
    return context.sync()
        .then(function() {
            console.log(page.webUrl);
        });
})
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});
OneNote.run(function (ctx) {        
    var app = ctx.application;

    // Gets the active page.
    var page = app.getActivePage();

    // Load ink words
    page.load('inkAnalysisOrNull/paragraphs/lines/words');

    return ctx.sync()
        .then(function() {
            if (!page.inkAnalysisOrNull.isNull)
                console.log(page.inkAnalysisOrNull.paragraphs.length);
        });
})
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

toJSON()

toJSON(): OneNote.Interfaces.PageData;
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.Page;
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.Page;
Returns