OneNote.Page class

Represents a OneNote page.

Extends

Remarks

[ API set: OneNoteApi 1.1 ]

Properties

classNotebookPageSource

Gets the ClassNotebookPageSource to the page.

clientUrl

The client url of the page.

contents

The collection of PageContent objects on the page. Read only

context

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

id

Gets the ID of the page.

inkAnalysisOrNull

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

pageLevel

Gets or sets the indentation level of the page.

parentSection

Gets the section that contains the page.

title

Gets or sets the title of the page.

webUrl

The web url of the page.

Methods

addOutline(left, top, html)

Adds an Outline to the page at the specified position.

analyzePage()

Return a JSON string with node ID and content in HTML format.

applyTranslation(translatedContent)

Inserts a new page with translated content.

copyToSection(destinationSection)

Copies this page to specified section.

copyToSectionAndSetClassNotebookPageSource(destinationSection)

Copies this page to specified section and sets ClassNotebookPageSource.

getRestApiId()

Gets the REST API ID.

hasTitleContent()

Does the page has content title.

insertPageAsSibling(location, title)

Inserts a new page before or after the current page.

insertPageAsSibling(locationString, title)

Inserts a new page before or after the current page.

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.

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 OneNote.Page object is an API object, the toJSON method returns a plain JavaScript object (typed as OneNote.Interfaces.PageData) 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.

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

classNotebookPageSource

Gets the ClassNotebookPageSource to the page.

readonly classNotebookPageSource: string;

Property Value

string

Remarks

[ API set: OneNoteApi 1.1 ]

clientUrl

The client url of the page.

readonly clientUrl: string;

Property Value

string

Remarks

[ API set: OneNoteApi 1.1 ]

contents

The collection of PageContent objects on the page. Read only

readonly contents: OneNote.PageContentCollection;

Property Value

Remarks

[ API set: OneNoteApi 1.1 ]

context

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

context: RequestContext;

Property Value

id

Gets the ID of the page.

readonly id: string;

Property Value

string

Remarks

[ API set: OneNoteApi 1.1 ]

inkAnalysisOrNull

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

readonly inkAnalysisOrNull: OneNote.InkAnalysis;

Property Value

Remarks

[ API set: OneNoteApi 1.1 ]

pageLevel

Gets or sets the indentation level of the page.

pageLevel: number;

Property Value

number

Remarks

[ API set: OneNoteApi 1.1 ]

parentSection

Gets the section that contains the page.

readonly parentSection: OneNote.Section;

Property Value

Remarks

[ API set: OneNoteApi 1.1 ]

title

Gets or sets the title of the page.

title: string;

Property Value

string

Remarks

[ API set: OneNoteApi 1.1 ]

webUrl

The web url of the page.

readonly webUrl: string;

Property Value

string

Remarks

[ API set: OneNoteApi 1.1 ]

Method Details

addOutline(left, top, html)

Adds an Outline to the page at the specified position.

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

Remarks

[ API set: OneNoteApi 1.1 ]

Examples

await OneNote.run(async (context) => {

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

    // Queue a command to add an outline with given html.
    const 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.
    await context.sync();
});

analyzePage()

Return a JSON string with node ID and content in HTML format.

analyzePage(): OfficeExtension.ClientResult<string>;

Returns

Remarks

[ API set: OneNoteApi 1.1 ]

applyTranslation(translatedContent)

Inserts a new page with translated content.

applyTranslation(translatedContent: string): void;

Parameters

translatedContent

string

Translated content of the page.

Returns

void

Remarks

[ API set: OneNoteApi 1.1 ]

copyToSection(destinationSection)

Copies this page to specified section.

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

Parameters

destinationSection
OneNote.Section

The section to copy this page to.

Returns

Remarks

[ API set: OneNoteApi 1.1 ]

Examples

await OneNote.run(async (context) => {
    const app = context.application;
    
    // Gets the active notebook.
    const notebook = app.getActiveNotebook();
    
    // Gets the active page.
    const page = app.getActivePage();
    
    // Queue a command to load sections under the notebook.
    notebook.load('sections');
    
    let newPage;
    
    // Run the queued commands, and return a promise to indicate task completion.
    await context.sync();

    const section = notebook.sections.items[0];
    
    // Copy page to the section.
    newPage = page.copyToSection(section);
    newPage.load('id');
    await context.sync();
    
    console.log(newPage.id);
});

copyToSectionAndSetClassNotebookPageSource(destinationSection)

Copies this page to specified section and sets ClassNotebookPageSource.

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

Parameters

destinationSection
OneNote.Section

Returns

Remarks

[ API set: OneNoteApi 1.1 ]

getRestApiId()

Gets the REST API ID.

getRestApiId(): OfficeExtension.ClientResult<string>;

Returns

Remarks

[ API set: OneNoteApi 1.1 ]

Examples

await OneNote.run(async (context) => {
    // Get the current page.
    const page = context.application.getActivePage();
    const restApiId = page.getRestApiId();

    await context.sync();
    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://learn.microsoft.com/archive/blogs/onenotedev/and-sharepoint-makes-three
});

hasTitleContent()

Does the page has content title.

hasTitleContent(): OfficeExtension.ClientResult<boolean>;

Returns

Remarks

[ API set: OneNoteApi 1.1 ]

insertPageAsSibling(location, title)

Inserts a new page before or after the current page.

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

Remarks

[ API set: OneNoteApi 1.1 ]

insertPageAsSibling(locationString, title)

Inserts a new page before or after the current page.

insertPageAsSibling(locationString: "Before" | "After", title: string): OneNote.Page;

Parameters

locationString

"Before" | "After"

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

title

string

The title of the new page.

Returns

Remarks

[ API set: OneNoteApi 1.1 ]

Examples

await OneNote.run(async (context) => {

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

    // Queue a command to add a new page after the active page.
    const 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.
    await context.sync();
    console.log("page is created with title: " + newPage.title);
});

load(options)

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

load(options?: OneNote.Interfaces.PageLoadOptions): OneNote.Page;

Parameters

options
OneNote.Interfaces.PageLoadOptions

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.

load(propertyNames?: string | string[]): OneNote.Page;

Parameters

propertyNames

string | string[]

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

Returns

Examples

await OneNote.run(async (context) => {

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

    // Queue a command to add a new page after the active page.
    const 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.
    await context.sync()
    for(let i=0; i < pageContents.items.length; i++) {
        const 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.");
        }
    }
});

load(propertyNamesAndPaths)

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

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): OneNote.Page;

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

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: Interfaces.PageUpdateData, options?: OfficeExtension.UpdateOptions): void;

Parameters

properties
OneNote.Interfaces.PageUpdateData

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.

set(properties: OneNote.Page): void;

Parameters

properties
OneNote.Page

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 OneNote.Page object is an API object, the toJSON method returns a plain JavaScript object (typed as OneNote.Interfaces.PageData) that contains shallow copies of any loaded child properties from the original object.

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'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.

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

untrack(): OneNote.Page;

Returns