OutlineApi
The Outline panel, headless: the bookmark tree, read whole and edited one bookmark at a time. A bookmark is addressed by its path — the indices that lead to it in the tree get() returns ([0] the first top-level bookmark, [0, 2] its third child). A viewer on the document follows each edit: its panel refreshes, it takes an undo step and fires documentChanged. The panel is described under Document features.
get() needs no feature, but without extract every title is ''. set, add, delete and setTitle need the edit-pages feature and refuse with FEATURE_NOT_LICENSED without it. Each of the four refuses a certified document with INVALID_STATE unless options.invalidateSignatures: no certification level allows bookmark changes.
namespacedoc.outline
Usage
TypeScript
for (const chapter of await doc.outline.get()) { console.log(chapter.title, '→ page', chapter.pageIndex); } await doc.outline.add('Appendix', doc.pageCount - 1);
Reading
get(): Promise<OutlineNode[]>
The bookmark tree. Without the
extract feature every title is '', so a tree read then and given back to set writes them blank: rename with setTitle. Needs no feature.Returns
Promise<OutlineNode[]> Each { title, pageIndex, children }; pageIndex is null when the bookmark has no page (it only groups children).DOCUMENT_CLOSED— the document has been closed.
TypeScript
const chapters = await doc.outline.get();
Editing
set(nodes: OutlineNode[], options?: SignedDocumentOptions): Promise<void>
Replace the whole tree. Keeps only titles, pages and nesting: each bookmark's zoom, color, style, other actions and open state are lost — use
add, delete and setTitle for single edits, which change one bookmark and nothing else. Needs the edit-pages feature.| Parameter | Type | Description |
|---|---|---|
| nodes | OutlineNode[] | The whole tree: { title, pageIndex, children } each. |
| options? | SignedDocumentOptions | { invalidateSignatures? }. |
Returns
Promise<void> FEATURE_NOT_LICENSED— the license lacksedit-pages.PAGE_ERROR— the change could not be written.DOCUMENT_CLOSED— the document has been closed.INVALID_STATE— a certified document, unlessoptions.invalidateSignatures(no certification level allows bookmark changes); or a progressive document still downloading.
TypeScript
await doc.outline.set([ { title: 'Cover', pageIndex: 0, children: [] }, { title: 'Terms', pageIndex: 4, children: [{ title: 'Payment', pageIndex: 5, children: [] }] }, ]);
add(title: string, pageIndex: number, options?: AddBookmarkOptions): Promise<number[]>
Add one bookmark, as the last child of the bookmark at
options.parentPath (omitted: top level), going to pageIndex. Needs the edit-pages feature.| Parameter | Type | Description |
|---|---|---|
| title | string | The bookmark's title. |
| pageIndex | number | The zero-based page it goes to. |
| options? | AddBookmarkOptions | parentPath (a path into get()'s tree; omitted, top level) and invalidateSignatures. |
Returns
Promise<number[]> The new bookmark's path, for delete() / setTitle().INVALID_ARGUMENT— a page index out of range, or aparentPaththat names no bookmark.FEATURE_NOT_LICENSED— the license lacksedit-pages.PAGE_ERROR— the change could not be written.DOCUMENT_CLOSED— the document has been closed.INVALID_STATE— a certified document, unlessoptions.invalidateSignatures(no certification level allows bookmark changes); or a progressive document still downloading.
TypeScript
const path = await doc.outline.add('Appendix', doc.pageCount - 1); await doc.outline.add('Tables', doc.pageCount - 1, { parentPath: path });
delete(path: number[], options?: SignedDocumentOptions): Promise<void>
Delete the bookmark at a path, its children with it. Needs the
edit-pages feature.| Parameter | Type | Description |
|---|---|---|
| path | number[] | The bookmark's path into get()'s tree. |
| options? | SignedDocumentOptions | { invalidateSignatures? }. |
Returns
Promise<void> INVALID_ARGUMENT— apaththat names no bookmark.FEATURE_NOT_LICENSED— the license lacksedit-pages.PAGE_ERROR— the change could not be written.DOCUMENT_CLOSED— the document has been closed.INVALID_STATE— a certified document, unlessoptions.invalidateSignatures(no certification level allows bookmark changes); or a progressive document still downloading.
TypeScript
await doc.outline.delete([0, 2]); // the first bookmark's third child
setTitle(path: number[], title: string, options?: SignedDocumentOptions): Promise<void>
Rename the bookmark at a path, in place. Needs the
edit-pages feature.| Parameter | Type | Description |
|---|---|---|
| path | number[] | The bookmark's path into get()'s tree. |
| title | string | The new title. |
| options? | SignedDocumentOptions | { invalidateSignatures? }. |
Returns
Promise<void> INVALID_ARGUMENT— apaththat names no bookmark.FEATURE_NOT_LICENSED— the license lacksedit-pages.PAGE_ERROR— the change could not be written.DOCUMENT_CLOSED— the document has been closed.INVALID_STATE— a certified document, unlessoptions.invalidateSignatures(no certification level allows bookmark changes); or a progressive document still downloading.
TypeScript
await doc.outline.setTitle([0], 'Introduction');