---
title: "DocumentContent"
version: "0.9.0"
url: "https://docs.laminapdf.com/reference/sdk/interfaces/documentcontent/"
---

# DocumentContent

Defined in: [packages/sdk/src/content.ts:39](https://github.com/laudebugs/laminapdf/blob/v0.9.0/packages/sdk/src/content.ts#L39)

The objects the document's pages draw, and edits to them ([Document.content](/reference/sdk/classes/document.md#content)). Pages are
0-based indexes; geometry is in page space: points from the top-left of the page as shown, y
down. Editing existing content is best effort: an object that clips what follows it, or that
would draw differently in its new place in the stacking order, is refused with
`content-not-editable` and a reason, and changes nothing.

## Since

0.5.0

## Methods

### add()

```ts
add(index, object): EditedJs;
```

Defined in: [packages/sdk/src/content.ts:212](https://github.com/laudebugs/laminapdf/blob/v0.9.0/packages/sdk/src/content.ts#L212)

Adds an image, a shape or a page of another PDF to page `index` as page content
(`addContentObject`): part of the page, printed and drawn by every reader, not a comment.
`object.matrix` places the object's space on the page: an image or a page fills the unit
square, so `[w, 0, 0, h, x, y]` draws it `w` by `h` points with its top-left corner at
`(x, y)`; a shape's path is in page space, so the identity draws it where its points are.
Add the bytes an image or a page names with [Document.addBlob](/reference/sdk/classes/document.md#addblob) first. For a page of
a PDF that needs a password, add that PDF with [Document.addSource](/reference/sdk/classes/document.md#addsource) and the password
instead, and give the source's ID as `blob`. If its limits forbid copying, the password
has to be its permissions password.

```ts
const blob = doc.addBlob(logoPng);
doc.content.add(0, {
  id: "logo",
  object: { image: { blob } },
  matrix: [144, 0, 0, 44, 72, 40],
  alt: { text: "Northwind" },
  modified: "D:20261118120000Z",
});
```

#### Parameters

##### index

`number`

##### object

[`NewContentObject`](/reference/sdk/interfaces/newcontentobject.md)

#### Returns

`EditedJs`

#### Throws

[LaminaPdfError](/reference/sdk/classes/laminapdferror.md) `content-id-in-use`, `content-object-invalid`,
`content-needs-alt-text` (a picture without `alt` in a PDF/UA-1 file), `unknown-blob`,
`owner-password-required` (a page of a PDF whose limits forbid copying), `invalid-op`;
as [Document.apply](/reference/sdk/classes/document.md#apply).

#### Since

0.7.0

***

### addBackground()

```ts
addBackground(pages, background): EditedJs;
```

Defined in: [packages/sdk/src/content.ts:314](https://github.com/laudebugs/laminapdf/blob/v0.9.0/packages/sdk/src/content.ts#L314)

Puts a background on `pages` (`addBackground`): text, or an image that covers the page, drawn
behind each page's content. Otherwise as [DocumentContent.addWatermark](/reference/sdk/interfaces/documentcontent.md#addwatermark).

#### Parameters

##### pages

readonly `number`[]

##### background

[`NewWatermark`](/reference/sdk/interfaces/newwatermark.md)

#### Returns

`EditedJs`

#### Throws

[LaminaPdfError](/reference/sdk/classes/laminapdferror.md) as [DocumentContent.addWatermark](/reference/sdk/interfaces/documentcontent.md#addwatermark).

#### Since

0.7.0

***

### added()

```ts
added(index): AddedObject[];
```

Defined in: [packages/sdk/src/content.ts:276](https://github.com/laudebugs/laminapdf/blob/v0.9.0/packages/sdk/src/content.ts#L276)

The objects Lamina PDF added to page `index`, in the order they paint, those behind the
page's content first: each with its ID, what it is, its matrix, opacity, layer, alternate text
and its box in page space. Works in every module.

#### Parameters

##### index

`number`

#### Returns

`AddedObject`[]

#### Throws

[LaminaPdfError](/reference/sdk/classes/laminapdferror.md) `page-index-out-of-range`; reading errors.

#### Since

0.7.0

***

### addText()

```ts
addText(index, text): EditedJs;
```

Defined in: [packages/sdk/src/content.ts:241](https://github.com/laudebugs/laminapdf/blob/v0.9.0/packages/sdk/src/content.ts#L241)

Adds text to page `index` as page content (`addText`), laid out in `rect`, a box in page
space: shaped and wrapped at the box's width, set in the first of `fonts` and, for a
character it lacks, the fonts after it (a symbol font, a font of another script), each
embedded as a subset that copies and searches as typed. Standard fonts need no bytes; add a
font's bytes with [Document.addBlob](/reference/sdk/classes/document.md#addblob) first and name them by the ID it returns. The
text is a paragraph in a tagged file, or an artifact for `tag: "artifact"`. Change or remove
it with [DocumentContent.update](/reference/sdk/interfaces/documentcontent.md#update) (`text`, `matrix`) and [DocumentContent.remove](/reference/sdk/interfaces/documentcontent.md#remove).

```ts
doc.content.addText(0, {
  id: "note",
  rect: [72, 72, 288, 120],
  runs: [{ text: "Reviewed " }, { text: "twice", bold: true }],
  fonts: ["helvetica"],
  modified: "D:20261118120000Z",
});
```

#### Parameters

##### index

`number`

##### text

[`NewText`](/reference/sdk/interfaces/newtext.md)

#### Returns

`EditedJs`

#### Throws

[LaminaPdfError](/reference/sdk/classes/laminapdferror.md) `content-id-in-use`, `content-glyph-missing` (a character in
none of the fonts), `content-font-not-embeddable` (a font whose licence forbids embedding),
`content-font-invalid`, `appearance-needs-text` (a font's bytes in a module without text
layout, or a character Helvetica, Times and Courier lack), `unknown-blob`, `invalid-op`; as
[Document.apply](/reference/sdk/classes/document.md#apply).

#### Since

0.7.0

***

### addWatermark()

```ts
addWatermark(pages, watermark): EditedJs;
```

Defined in: [packages/sdk/src/content.ts:304](https://github.com/laudebugs/laminapdf/blob/v0.9.0/packages/sdk/src/content.ts#L304)

Puts a watermark on `pages` (`addWatermark`): text, or an image added with
[Document.addBlob](/reference/sdk/classes/document.md#addblob), centred on each page and drawn in front of its content, turned by
`angle` and faded by `opacity`. It is part of the page, printed and drawn by every reader, and
an artifact in a tagged file. With `hideable` a reader's layers panel can switch it off.
Change it with [DocumentContent.updatePageMark](/reference/sdk/interfaces/documentcontent.md#updatepagemark) and take it off with
[DocumentContent.deletePageMark](/reference/sdk/interfaces/documentcontent.md#deletepagemark), by `id`, which is the same on every page.

```ts
doc.content.addWatermark([0, 1, 2], {
  id: "draft",
  mark: { text: { text: "DRAFT", size: 96, color: [0.8, 0, 0] } },
  opacity: 0.3,
  angle: 45,
  hideable: true,
  modified: "D:20261118120000Z",
});
```

#### Parameters

##### pages

readonly `number`[]

##### watermark

[`NewWatermark`](/reference/sdk/interfaces/newwatermark.md)

#### Returns

`EditedJs`

#### Throws

[LaminaPdfError](/reference/sdk/classes/laminapdferror.md) `content-id-in-use`, `content-glyph-missing`,
`content-font-not-embeddable`, `content-font-invalid`, `content-object-invalid` (an image
that isn't one), `appearance-needs-text`, `unknown-blob`, `invalid-op`,
`page-index-out-of-range`; as [Document.apply](/reference/sdk/classes/document.md#apply).

#### Since

0.7.0

***

### applyBates()

```ts
applyBates(pages, bates): EditedJs;
```

Defined in: [packages/sdk/src/content.ts:344](https://github.com/laudebugs/laminapdf/blob/v0.9.0/packages/sdk/src/content.ts#L344)

Numbers `pages` with a Bates number (`applyBates`): `bates.start` on the first page named,
one more on each after it, in the order given. Number many files by calling it on each with
the `start` the last one reached.

#### Parameters

##### pages

readonly `number`[]

##### bates

[`NewBates`](/reference/sdk/interfaces/newbates.md)

#### Returns

`EditedJs`

#### Throws

[LaminaPdfError](/reference/sdk/classes/laminapdferror.md) as [DocumentContent.addWatermark](/reference/sdk/interfaces/documentcontent.md#addwatermark).

#### Since

0.7.0

***

### deletePageMark()

```ts
deletePageMark(pages, id): EditedJs;
```

Defined in: [packages/sdk/src/content.ts:366](https://github.com/laudebugs/laminapdf/blob/v0.9.0/packages/sdk/src/content.ts#L366)

Takes the mark `id` off `pages` (`deletePageMark`). It stays in the file's earlier revisions
until a full save (`stillInEarlierRevisions`).

#### Parameters

##### pages

readonly `number`[]

##### id

`string`

#### Returns

`EditedJs`

#### Throws

[LaminaPdfError](/reference/sdk/classes/laminapdferror.md) `unknown-page-mark`, `page-index-out-of-range`; as
[Document.apply](/reference/sdk/classes/document.md#apply).

#### Since

0.7.0

***

### edit()

```ts
edit(index, edits): EditedJs;
```

Defined in: [packages/sdk/src/content.ts:181](https://github.com/laudebugs/laminapdf/blob/v0.9.0/packages/sdk/src/content.ts#L181)

Makes `edits` on page `index` in one transaction (`editContent`), in order. Each names its
object as [DocumentContent.objects](/reference/sdk/interfaces/documentcontent.md#objects) gave it before the edit; a name that no longer
matches fails with `content-object-stale`. Only the objects named are written again: the
rest of the page keeps its bytes, and a content stream another page also draws stays as it
was there. What a deletion removes stays in the file's earlier revisions until a full save
(`stillInEarlierRevisions`).

#### Parameters

##### index

`number`

##### edits

readonly `ContentEdit`[]

#### Returns

`EditedJs`

#### Throws

[LaminaPdfError](/reference/sdk/classes/laminapdferror.md) `content-object-stale`, `content-not-editable`,
`unknown-blob`; as [Document.apply](/reference/sdk/classes/document.md#apply).

#### Since

0.5.0

***

### editText()

```ts
editText(
   index, 
   run, 
   text, 
   fonts?
): EditedJs;
```

Defined in: [packages/sdk/src/content.ts:82](https://github.com/laudebugs/laminapdf/blob/v0.9.0/packages/sdk/src/content.ts#L82)

Makes `run` on page `index` show `text` (`editText`), in the font it is set in: every
character must be one the font can draw (for an embedded subset, one the document already
shows in it; a space it can't draw becomes a word-sized gap). The text after the run in the
same text object moves by the width difference; text another object places on the line stays
put, and the lines below stay where they were. Empty text deletes the run. To change part of a run, name its glyphs: `start` and
`end` within the run's. The old text stays in the file's earlier revisions until a full save.

Pass `fonts` to let a character the run's font lacks come from another font: a full copy of
the run's own font (its bytes from [Document.addBlob](/reference/sdk/classes/document.md#addblob)) adds a new subset of it; any
other font (`"helvetica"`, `"times"`, `"courier"` or a blob ID) substitutes. Nothing is
substituted that `fonts` doesn't name, and the returned `textEdits` say which characters
were drawn in which font; [DocumentContent.planEditText](/reference/sdk/interfaces/documentcontent.md#planedittext) says so before the edit.

#### Parameters

##### index

`number`

##### run

`TextRunRef`

##### text

`string`

##### fonts?

readonly `string`[]

#### Returns

`EditedJs`

#### Throws

[LaminaPdfError](/reference/sdk/classes/laminapdferror.md) `missing-glyph` for a character no font can draw,
`content-not-editable` with the reason for a read-only run, `content-object-stale`; as
[Document.apply](/reference/sdk/classes/document.md#apply).

#### Since

0.5.0

***

### hitTest()

```ts
hitTest(index, at): ObjectRef[];
```

Defined in: [packages/sdk/src/content.ts:166](https://github.com/laudebugs/laminapdf/blob/v0.9.0/packages/sdk/src/content.ts#L166)

The objects of page `index` at `at`, topmost first: a point `[x, y]` (an object within 2
points of it counts), or a rectangle `[x0, y0, x1, y1]` (every object whose box meets it).

#### Parameters

##### index

`number`

##### at

\| readonly \[`number`, `number`, `number`, `number`\]
\| readonly \[`number`, `number`\]

#### Returns

`ObjectRef`[]

#### Throws

[LaminaPdfError](/reference/sdk/classes/laminapdferror.md) as [DocumentContent.objects](/reference/sdk/interfaces/documentcontent.md#objects).

#### Since

0.5.0

***

### objects()

```ts
objects(index): PageObjectJs[];
```

Defined in: [packages/sdk/src/content.ts:49](https://github.com/laudebugs/laminapdf/blob/v0.9.0/packages/sdk/src/content.ts#L49)

The objects page `index` draws, in painting order: paths, text objects, images, forms and
shadings, each with its name for an edit, its box and, when it can't be moved, why.

#### Parameters

##### index

`number`

#### Returns

`PageObjectJs`[]

#### Throws

[LaminaPdfError](/reference/sdk/classes/laminapdferror.md) `extract-module-not-loaded`, `page-index-out-of-range`; reading
errors.

#### Since

0.5.0

***

### pageMarks()

```ts
pageMarks(index): PageMarkInfo[];
```

Defined in: [packages/sdk/src/content.ts:376](https://github.com/laudebugs/laminapdf/blob/v0.9.0/packages/sdk/src/content.ts#L376)

The page marks on page `index`, in the order they paint, backgrounds first: each with its ID,
what it is and whether a reader's layers panel can hide it. Works in every module.

#### Parameters

##### index

`number`

#### Returns

`PageMarkInfo`[]

#### Throws

[LaminaPdfError](/reference/sdk/classes/laminapdferror.md) `page-index-out-of-range`; reading errors.

#### Since

0.7.0

***

### planEditText()

```ts
planEditText(
   index, 
   run, 
   text, 
   fonts?
): TextEditReport;
```

Defined in: [packages/sdk/src/content.ts:94](https://github.com/laudebugs/laminapdf/blob/v0.9.0/packages/sdk/src/content.ts#L94)

What [DocumentContent.editText](/reference/sdk/interfaces/documentcontent.md#edittext) would do, without doing it: how faithful the result
would be (`fidelity`), the characters the run's font can't draw with the font that would
draw each (`substitutions`) and how many points wider the line would grow (`grewBy`). Show
it before committing the edit, so a font is never changed silently.

#### Parameters

##### index

`number`

##### run

`TextRunRef`

##### text

`string`

##### fonts?

readonly `string`[]

#### Returns

`TextEditReport`

#### Throws

[LaminaPdfError](/reference/sdk/classes/laminapdferror.md) as [DocumentContent.editText](/reference/sdk/interfaces/documentcontent.md#edittext), but nothing is changed.

#### Since

0.7.0

***

### planReplaceText()

```ts
planReplaceText(edits, fonts?): ReplacementPlanJs[];
```

Defined in: [packages/sdk/src/content.ts:120](https://github.com/laudebugs/laminapdf/blob/v0.9.0/packages/sdk/src/content.ts#L120)

What [DocumentContent.replaceText](/reference/sdk/interfaces/documentcontent.md#replacetext) would do for each match, without doing it, in the
order of `edits`: the match's `report`, or the `error` that makes it one to skip. Each match
is judged alone in the document as it is. Needs a document opened while the extract or text
module was loaded.

#### Parameters

##### edits

readonly [`TextReplacement`](/reference/sdk/interfaces/textreplacement.md)[]

##### fonts?

readonly `string`[]

#### Returns

`ReplacementPlanJs`[]

#### Since

0.8.0

***

### remove()

```ts
remove(index, id): EditedJs;
```

Defined in: [packages/sdk/src/content.ts:265](https://github.com/laudebugs/laminapdf/blob/v0.9.0/packages/sdk/src/content.ts#L265)

Takes the object `id` that Lamina PDF added to page `index` off the page
(`deleteContentObject`). It stays in the file's earlier revisions until a full save
(`stillInEarlierRevisions`).

#### Parameters

##### index

`number`

##### id

`string`

#### Returns

`EditedJs`

#### Throws

[LaminaPdfError](/reference/sdk/classes/laminapdferror.md) `unknown-content-object`; as [Document.apply](/reference/sdk/classes/document.md#apply).

#### Since

0.7.0

***

### replaceText()

```ts
replaceText(edits, fonts?): EditedJs;
```

Defined in: [packages/sdk/src/content.ts:110](https://github.com/laudebugs/laminapdf/blob/v0.9.0/packages/sdk/src/content.ts#L110)

Replaces the text of many matches, on any pages, in one step (`replaceText`, one undo): a
search-and-replace names each match as the glyphs it covers and the text that takes their
place. Each is an [DocumentContent.editText](/reference/sdk/interfaces/documentcontent.md#edittext) of those glyphs, in the font they are set
in; matches in one object may follow one another and may differ in length. It is all or
nothing: one match that can't be replaced fails the op and changes nothing, so call
[DocumentContent.planReplaceText](/reference/sdk/interfaces/documentcontent.md#planreplacetext) first and send the ones that can.

#### Parameters

##### edits

readonly [`TextReplacement`](/reference/sdk/interfaces/textreplacement.md)[]

##### fonts?

readonly `string`[]

#### Returns

`EditedJs`

#### Throws

[LaminaPdfError](/reference/sdk/classes/laminapdferror.md) `invalid-op` for no edits or two matches that share a glyph,
`missing-glyph`, `content-not-editable` with the reason, `content-object-stale`; as
[Document.apply](/reference/sdk/classes/document.md#apply).

#### Since

0.8.0

***

### setAlt()

```ts
setAlt(
   index, 
   object, 
   alt
): EditedJs;
```

Defined in: [packages/sdk/src/content.ts:156](https://github.com/laudebugs/laminapdf/blob/v0.9.0/packages/sdk/src/content.ts#L156)

Sets the alternative text of the figure that owns `object` on page `index` (`setAlt`): the
`Figure` element of the object's marked content, or the nearest one above it, which screen
readers read in place of the image. The text a figure had is replaced, and the text is the
figure's: objects that share one figure (a chart drawn as many paths) all take the new text.
PageObject.alt reads the current text. `alt` isn't empty and holds at most 2,000
characters. The page's content isn't changed, and a signed file
that forbids changes to its structure refuses the edit when saved, as for any other edit.

#### Parameters

##### index

`number`

##### object

`ObjectRef`

##### alt

`string`

#### Returns

`EditedJs`

#### Throws

[LaminaPdfError](/reference/sdk/classes/laminapdferror.md) `invalid-op` for empty or overlong text, an untagged file, an
object outside marked content, one no `Figure` owns, one whose marked content belongs to
more than one `Figure` and a form that is tagged itself (its own `/StructParents`);
`content-object-stale`; as
[Document.apply](/reference/sdk/classes/document.md#apply).

#### Since

0.7.0

***

### setHeaderFooter()

```ts
setHeaderFooter(pages, headerFooter): EditedJs;
```

Defined in: [packages/sdk/src/content.ts:333](https://github.com/laudebugs/laminapdf/blob/v0.9.0/packages/sdk/src/content.ts#L333)

Puts a header and footer on `pages` (`setHeaderFooter`): six slots of text with the fields
`{page}`, `{pages}`, `{label}`, `{date}` and `{file}`, filled when the edit is applied.

```ts
doc.content.setHeaderFooter([0, 1, 2], {
  id: "folio",
  slots: [null, null, null, null, "Page {page} of {pages}", null],
  size: 9,
  modified: "D:20261118120000Z",
});
```

#### Parameters

##### pages

readonly `number`[]

##### headerFooter

[`NewHeaderFooter`](/reference/sdk/interfaces/newheaderfooter.md)

#### Returns

`EditedJs`

#### Throws

[LaminaPdfError](/reference/sdk/classes/laminapdferror.md) as [DocumentContent.addWatermark](/reference/sdk/interfaces/documentcontent.md#addwatermark).

#### Since

0.7.0

***

### setTextStyle()

```ts
setTextStyle(
   index, 
   runs, 
   style
): EditedJs;
```

Defined in: [packages/sdk/src/content.ts:137](https://github.com/laudebugs/laminapdf/blob/v0.9.0/packages/sdk/src/content.ts#L137)

Changes how `runs` on page `index` look (`setTextStyle`): font (`"helvetica"`, `"times"`,
`"courier"` or a blob ID, embedded as a new subset), `size` in points, `color`, `bold`,
`italic` (the face of a standard font), `underline`, `baseline` (`"normal"`, `"super"`,
`"sub"`), `align` and `lineSpacing` (a multiple of the glyphs' size) for the lines of the
runs' text object. The text stays as it is; the glyphs after a run on its line move by the
width difference. Each field is optional and changes only what it names.

#### Parameters

##### index

`number`

##### runs

readonly `TextRunRef`[]

##### style

[`TextStyle`](/reference/sdk/type-aliases/textstyle.md)

#### Returns

`EditedJs`

#### Throws

[LaminaPdfError](/reference/sdk/classes/laminapdferror.md) `content-not-editable` with the reason, `content-object-stale`,
`missing-glyph` when the new font lacks a character, `invalid-op` for a style that
names nothing or can't be done (taking an underline off, bold on a font with no bold
face to take); as [Document.apply](/reference/sdk/classes/document.md#apply).

#### Since

0.7.0

***

### textRuns()

```ts
textRuns(index): ContentTextRunJs[];
```

Defined in: [packages/sdk/src/content.ts:60](https://github.com/laudebugs/laminapdf/blob/v0.9.0/packages/sdk/src/content.ts#L60)

The runs of text page `index` shows, in the order the page draws them: each with its name for
[DocumentContent.editText](/reference/sdk/interfaces/documentcontent.md#edittext), its text, box, font, size and line and, when it can't be
edited, why. Text inside a form isn't listed.

#### Parameters

##### index

`number`

#### Returns

`ContentTextRunJs`[]

#### Throws

[LaminaPdfError](/reference/sdk/classes/laminapdferror.md) as [DocumentContent.objects](/reference/sdk/interfaces/documentcontent.md#objects).

#### Since

0.5.0

***

### update()

```ts
update(
   index, 
   id, 
   changes
): EditedJs;
```

Defined in: [packages/sdk/src/content.ts:254](https://github.com/laudebugs/laminapdf/blob/v0.9.0/packages/sdk/src/content.ts#L254)

Changes the object `id` that Lamina PDF added to page `index` (`updateContentObject`), before
or after a save: its matrix, opacity, an image's crop, a shape's fill and stroke, new bytes,
its alternate text or its place among the objects on its layer. Fields left out keep their
values; `null` removes a crop, a fill or a stroke.

#### Parameters

##### index

`number`

##### id

`string`

##### changes

[`ContentChanges`](/reference/sdk/interfaces/contentchanges.md)

#### Returns

`EditedJs`

#### Throws

[LaminaPdfError](/reference/sdk/classes/laminapdferror.md) `unknown-content-object`, `invalid-op` (a change for another
kind of object); as [DocumentContent.add](/reference/sdk/interfaces/documentcontent.md#add).

#### Since

0.7.0

***

### updatePageMark()

```ts
updatePageMark(
   pages, 
   id, 
   mark, 
   modified
): EditedJs;
```

Defined in: [packages/sdk/src/content.ts:355](https://github.com/laudebugs/laminapdf/blob/v0.9.0/packages/sdk/src/content.ts#L355)

Replaces the mark `id` on `pages` with `mark`, of the same kind (`updatePageMark`), before or
after a save. It is drawn again where the old one was drawn.

#### Parameters

##### pages

readonly `number`[]

##### id

`string`

##### mark

`PageMark`

##### modified

`string`

#### Returns

`EditedJs`

#### Throws

[LaminaPdfError](/reference/sdk/classes/laminapdferror.md) `unknown-page-mark`, `invalid-op` (a mark of another kind); as
[DocumentContent.addWatermark](/reference/sdk/interfaces/documentcontent.md#addwatermark).

#### Since

0.7.0
