---
title: "Programmatic document editing in Document Authoring"
canonical_url: "https://www.nutrient.io/guides/document-authoring/editing-content/programmatic-editing/"
md_url: "https://www.nutrient.io/guides/document-authoring/editing-content/programmatic-editing.md"
last_updated: "2026-07-08T00:00:00.000Z"
description: "Learn how to use document transactions in Document Authoring to format paragraphs, work with shapes, manage comment threads, and run review-mode edits programmatically."
---

# Edit documents programmatically

Document Authoring provides a programmatic API for reading and updating document content with [`DocAuthDocument.transaction()`](https://www.nutrient.io/api/document-authoring/types/docauthdocument/#transaction). Transactions are atomic and isolated until committed. Each transaction gives you access to a draft document you can inspect or modify.

Before you start, make sure the Document Authoring library is installed and running in your app. If you haven’t set it up yet, refer to the [getting started](https://www.nutrient.io/sdk/document-authoring/getting-started.md) guide.

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

## Run a transaction

Use [`DocAuthDocument.transaction()`](https://www.nutrient.io/api/document-authoring/types/docauthdocument/#transaction) to work with a draft document. Return `true` to commit the transaction:

```js

// 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 every programmatic edit inside a transaction. Use these guides for specific editing tasks:

- [Text and formatting](https://www.nutrient.io/guides/document-authoring/editing-content/text-and-formatting.md) — Set text, character formatting, and paragraph styles.

- [Find and replace](https://www.nutrient.io/guides/document-authoring/editing-content/find-and-replace.md) — Search and replace with strings, regular expressions, or callbacks.

- [Lists](https://www.nutrient.io/guides/document-authoring/editing-content/lists.md) — Create, update, and read bullet and numbered lists.

- [Tables](https://www.nutrient.io/guides/document-authoring/editing-content/tables.md) — Build tables and add or remove rows and columns.

- [Images and shapes](https://www.nutrient.io/guides/document-authoring/editing-content/images-and-shapes.md) — Resize images and restyle shapes.

- [Sections and page setup](https://www.nutrient.io/guides/document-authoring/page-layout/sections-and-page-setup.md) — Set page size, page margins, and header/footer distances.

- [Headers and footers](https://www.nutrient.io/guides/document-authoring/page-layout/headers-and-footers.md) — Edit existing header and footer containers for each section.

- [Footnotes and endnotes](https://www.nutrient.io/guides/document-authoring/editing-content/footnotes-and-endnotes.md) — Read and edit note content.

- [Copy/paste and HTML interoperability](https://www.nutrient.io/guides/document-authoring/editing-content/copy-paste-and-html-interoperability.md) — Read the selection and insert content, including structured fragments.

- [Programmatic comments](https://www.nutrient.io/guides/document-authoring/review-and-collaboration/programmatic-comments.md) — Query, create, and resolve comment threads and author tracked-change edits.

## Learn more

- [Document Authoring API reference](https://www.nutrient.io/api/document-authoring/)

- [Programmatic API types](https://www.nutrient.io/api/document-authoring/modules/programmatic/)
---

## Related pages

- [Use copy/paste and HTML interoperability](/guides/document-authoring/editing-content/copy-paste-and-html-interoperability.md)
- [Work with images and shapes](/guides/document-authoring/editing-content/images-and-shapes.md)
- [Find and replace text](/guides/document-authoring/editing-content/find-and-replace.md)
- [Work with footnotes and endnotes](/guides/document-authoring/editing-content/footnotes-and-endnotes.md)
- [Work with tables](/guides/document-authoring/editing-content/tables.md)
- [Work with lists](/guides/document-authoring/editing-content/lists.md)
- [Format text](/guides/document-authoring/editing-content/text-and-formatting.md)

