Skip to content
Document Authoring DA  API Docs v1.21.0
npmGitHub

DocAuthDocument

DocAuthDocument:

A document instance. Holds the content and provides methods for saving, exporting to PDF/DOCX, and more.

Create documents via DocAuthEditor and/or DocAuthSystem.

getParticipant()

>= v1.20.0Section titled “getParticipant()”

getParticipant(): Participant

Returns the participant currently acting on this document.

The participant determines whether programmatic transactions and editor input may mutate or adjudicate the document. The author is only a label; hosts must bind participants to authenticated users themselves because the SDK does not authenticate.

Participant


setParticipant()

>= v1.20.0Section titled “setParticipant()”

setParticipant(participant): void

Sets the participant that acts on subsequent programmatic transactions and editor input for this document.

Owners have full access. Reviewers may create tracked changes and comments and withdraw their own pending suggestions, but may not accept or reject suggestions or make untracked content changes. Readers are read-only. The author is only a label; hosts must bind participants to authenticated users themselves because the SDK does not authenticate.

Participant

void


saveDocument(): Promise<object>

Returns the current document in the Document Authoring format as a JavaScript object. This object can be safely persisted.

Promise<object>

DocJSON guide


saveDocumentJSONString()

>= v1.20.0Section titled “saveDocumentJSONString()”

saveDocumentJSONString(options?): Promise<string>

Returns the current document in the Document Authoring format as a JSON string. This string can be safely persisted.

Pass { canonical: true } to return the canonical DocJSON string used as the content identity for transaction report digests. Omitting the option preserves the existing JSON string output.

SaveDocumentJSONStringOptions

Optional JSON serialization options.

Promise<string>


exportPDF(options?): Promise<ArrayBuffer>

Exports a snapshot of the current document as a PDF file.

ExportPDFOptions

Promise<ArrayBuffer>

PDF export guide


exportDOCX(options?): Promise<ArrayBuffer>

Exports a snapshot of the current document as a DOCX file.

ExportDOCXOptions

Promise<ArrayBuffer>

DOCX export guide


export(config): Promise<ArrayBuffer>

Exports a snapshot of the current document in the specified format.

ExportConfig

Promise<ArrayBuffer>

ExportConfig


transaction()

>= v1.10.0Section titled “transaction()”

transaction<T>(callback, options?): Promise<T>

Executes a transaction to programmatically read or modify the document.

T = void

TransactionCallback<T>

A TransactionCallback function that receives a draft document

TransactionOptions

Transaction options.

Promise<T>

A Promise that resolves to the result value from the callback

Provides programmatic access to the document structure through a draft document that can be read and modified. Changes are atomic and isolated until the transaction commits.

The callback executes after all pending transactions and input have been processed. While the callback runs, document access is blocked, preventing any UI interactions until the transaction completes.

await doc.transaction(async ({ draft }) => {
const section = draft.body().sections()[0];
const para = section.content().addParagraph();
para.asTextView().setText('Hello, World!');
return { commit: true };
});

transactionWithReport()

>= v1.20.0Section titled “transactionWithReport()”

transactionWithReport<T>(callback, options?): Promise<TransactionWithReportResult<T>>

Executes a document transaction and returns its callback result with a verifiable report.

T = void

TransactionCallback<T>

A TransactionCallback function that receives a draft document.

TransactionOptions

Transaction options.

Promise<TransactionWithReportResult<T>>

The callback result and transaction report.

The report’s beforeDigest and afterDigest identify the document’s canonical DocJSON content, including its model and resources. To verify a saved document, hash the exact string returned by saveDocumentJSONString({ canonical: true }) with SHA-256.

Report generation is opt-in because it serializes and hashes the document before and after the transaction. DocAuthDocument.transaction remains digest-free. Report txId values are scoped to the current document session and are not stable across sessions.


docAuthSystem(): DocAuthSystem

The DocAuthSystem this document is bound to.

DocAuthSystem


on(event, handler): DocAuthDocument

Adds an event listener that will be called every time the specified document event is emitted.

The document starts tracking events when its first listener is added and stops after its last listener is removed. Adding a listener later uses the current document state as the new baseline.

EventName

(payload: EventPayload) => void

DocAuthDocument

The document instance for method chaining.

document
.on('revision.accepted', ({ ids, origin }) => {
console.log('Accepted revisions', ids, origin);
})
.on('content.change', () => console.log('Document changed'));
Event nameEvent payloadDescription
revision.createdRevisionEventPayloadFired when one or more tracked-change revisions are created.
revision.editedRevisionEventPayloadFired when one or more existing tracked-change revisions are edited.
revision.acceptedRevisionEventPayloadFired when one or more tracked-change revisions are accepted.
revision.rejectedRevisionEventPayloadFired when one or more tracked-change revisions are rejected.
revision.withdrawnRevisionEventPayloadFired when one or more tracked-change revisions are withdrawn.
comment.threadAddedCommentEventPayloadFired when one or more comment threads are added.
comment.repliedCommentEventPayloadFired when one or more replies are added to comment threads.
comment.editedCommentEventPayloadFired when the text of one or more comments or replies is edited.
comment.resolvedCommentEventPayloadFired when one or more comment threads are resolved.
comment.unresolvedCommentEventPayloadFired when one or more comment threads are marked unresolved.
comment.removed`CommentEventPayload & { reason: “removed""anchor-deleted” }`
content.changenoneFired after every committed transaction following document initialization.

off(event, handler?): DocAuthDocument

Removes a document event listener. If no handler is provided, removes all listeners for the event.

EventName

(payload: EventPayload) => void

DocAuthDocument

The document instance for method chaining.

const handleAccepted = ({ ids }: RevisionEventPayload) => console.log(ids);
document.on('revision.accepted', handleAccepted);
// Remove one handler.
document.off('revision.accepted', handleAccepted);
// Remove every handler for this event.
document.off('revision.accepted');
Event nameEvent payloadDescription
revision.createdRevisionEventPayloadFired when one or more tracked-change revisions are created.
revision.editedRevisionEventPayloadFired when one or more existing tracked-change revisions are edited.
revision.acceptedRevisionEventPayloadFired when one or more tracked-change revisions are accepted.
revision.rejectedRevisionEventPayloadFired when one or more tracked-change revisions are rejected.
revision.withdrawnRevisionEventPayloadFired when one or more tracked-change revisions are withdrawn.
comment.threadAddedCommentEventPayloadFired when one or more comment threads are added.
comment.repliedCommentEventPayloadFired when one or more replies are added to comment threads.
comment.editedCommentEventPayloadFired when the text of one or more comments or replies is edited.
comment.resolvedCommentEventPayloadFired when one or more comment threads are resolved.
comment.unresolvedCommentEventPayloadFired when one or more comment threads are marked unresolved.
comment.removed`CommentEventPayload & { reason: “removed""anchor-deleted” }`
content.changenoneFired after every committed transaction following document initialization.

once(event, handler): DocAuthDocument

Adds an event listener that will be called only once when the specified document event is emitted. The listener is automatically removed after being called.

EventName

(payload: EventPayload) => void

DocAuthDocument

The document instance for method chaining.

document.once('comment.threadAdded', ({ ids }) => {
console.log('First added comment thread', ids);
});
Event nameEvent payloadDescription
revision.createdRevisionEventPayloadFired when one or more tracked-change revisions are created.
revision.editedRevisionEventPayloadFired when one or more existing tracked-change revisions are edited.
revision.acceptedRevisionEventPayloadFired when one or more tracked-change revisions are accepted.
revision.rejectedRevisionEventPayloadFired when one or more tracked-change revisions are rejected.
revision.withdrawnRevisionEventPayloadFired when one or more tracked-change revisions are withdrawn.
comment.threadAddedCommentEventPayloadFired when one or more comment threads are added.
comment.repliedCommentEventPayloadFired when one or more replies are added to comment threads.
comment.editedCommentEventPayloadFired when the text of one or more comments or replies is edited.
comment.resolvedCommentEventPayloadFired when one or more comment threads are resolved.
comment.unresolvedCommentEventPayloadFired when one or more comment threads are marked unresolved.
comment.removed`CommentEventPayload & { reason: “removed""anchor-deleted” }`
content.changenoneFired after every committed transaction following document initialization.