This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/document-authoring/editing-content/programmatic-editing.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. Programmatic document editing in Document Authoring

Nutrient Document Authoring SDK provides a programmatic API for reading and updating document content with DocAuthDocument.transaction(). Transactions stay atomic and isolated until you commit them, and each one gives you access to a draft document.

Before you start, install Nutrient Document Authoring SDK and load it in your app. If you haven’t set it up, refer to the getting started guide.

The examples omit error handling. Add error handling before you use this code in production.

Run a transaction

Use DocAuthDocument.transaction() to work with a draft document. Return true to commit the transaction.

// Assuming the `editor` instance exists.
const currentDoc = editor.currentDocument();
await currentDoc.transaction(async ({ draft }) => {
const paragraph = draft.body().content().addParagraph();
paragraph.asTextView().setText('Created in a transaction.');
return true;
});

Choose an editing operation

Run edits that use the draft document API inside a transaction. Editor-selection operations, such as copying or inserting content at the cursor, use the editor APIs directly. Refer to these guides for specific editing tasks:

  • Refer to the text and formatting guide to set text, character formatting, and paragraph styles.
  • Refer to the find and replace guide to search and replace with strings, regular expressions, or callbacks.
  • Refer to the lists guide to create, update, and read bullet and numbered lists.
  • Refer to the tables guide to build tables and add or remove rows and columns.
  • Refer to the images and shapes guide to resize images and restyle shapes.
  • Refer to the sections and page setup guide to set page size, page margins, and header/footer distances.
  • Refer to the headers and footers guide to edit header and footer containers for each section.
  • Refer to the footnotes and endnotes guide to read and edit note content.
  • Refer to the copy/paste and HTML interoperability guide to read the selection and insert structured fragments.
  • Refer to the programmatic comments guide to query, create, and resolve comment threads and author tracked-change edits.
  • Refer to the transaction reports guide to record canonical content digests and transaction changes.

Learn more

Use these references for API details: