DocumentContent
Defined in: packages/sdk/src/content.ts:39
The objects the document’s pages draw, and edits to them (Document.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.
0.5.0
Methods
Section titled “Methods”add(index, object): EditedJs;Defined in: packages/sdk/src/content.ts:212
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 first. For a page of
a PDF that needs a password, add that PDF with Document.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.
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
Section titled “Parameters”number
object
Section titled “object”Returns
Section titled “Returns”EditedJs
Throws
Section titled “Throws”LaminaPdfError 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.
0.7.0
addBackground()
Section titled “addBackground()”addBackground(pages, background): EditedJs;Defined in: packages/sdk/src/content.ts:314
Puts a background on pages (addBackground): text, or an image that covers the page, drawn
behind each page’s content. Otherwise as DocumentContent.addWatermark.
Parameters
Section titled “Parameters”readonly number[]
background
Section titled “background”Returns
Section titled “Returns”EditedJs
Throws
Section titled “Throws”LaminaPdfError as DocumentContent.addWatermark.
0.7.0
added()
Section titled “added()”added(index): AddedObject[];Defined in: packages/sdk/src/content.ts:276
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
Section titled “Parameters”number
Returns
Section titled “Returns”AddedObject[]
Throws
Section titled “Throws”LaminaPdfError page-index-out-of-range; reading errors.
0.7.0
addText()
Section titled “addText()”addText(index, text): EditedJs;Defined in: packages/sdk/src/content.ts:241
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 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 (text, matrix) and DocumentContent.remove.
doc.content.addText(0, { id: "note", rect: [72, 72, 288, 120], runs: [{ text: "Reviewed " }, { text: "twice", bold: true }], fonts: ["helvetica"], modified: "D:20261118120000Z",});Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”EditedJs
Throws
Section titled “Throws”LaminaPdfError 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.
0.7.0
addWatermark()
Section titled “addWatermark()”addWatermark(pages, watermark): EditedJs;Defined in: packages/sdk/src/content.ts:304
Puts a watermark on pages (addWatermark): text, or an image added with
Document.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 and take it off with
DocumentContent.deletePageMark, by id, which is the same on every page.
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
Section titled “Parameters”readonly number[]
watermark
Section titled “watermark”Returns
Section titled “Returns”EditedJs
Throws
Section titled “Throws”LaminaPdfError 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.
0.7.0
applyBates()
Section titled “applyBates()”applyBates(pages, bates): EditedJs;Defined in: packages/sdk/src/content.ts:344
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
Section titled “Parameters”readonly number[]
Returns
Section titled “Returns”EditedJs
Throws
Section titled “Throws”LaminaPdfError as DocumentContent.addWatermark.
0.7.0
deletePageMark()
Section titled “deletePageMark()”deletePageMark(pages, id): EditedJs;Defined in: packages/sdk/src/content.ts:366
Takes the mark id off pages (deletePageMark). It stays in the file’s earlier revisions
until a full save (stillInEarlierRevisions).
Parameters
Section titled “Parameters”readonly number[]
string
Returns
Section titled “Returns”EditedJs
Throws
Section titled “Throws”LaminaPdfError unknown-page-mark, page-index-out-of-range; as
Document.apply.
0.7.0
edit()
Section titled “edit()”edit(index, edits): EditedJs;Defined in: packages/sdk/src/content.ts:181
Makes edits on page index in one transaction (editContent), in order. Each names its
object as DocumentContent.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
Section titled “Parameters”number
readonly ContentEdit[]
Returns
Section titled “Returns”EditedJs
Throws
Section titled “Throws”LaminaPdfError content-object-stale, content-not-editable,
unknown-blob; as Document.apply.
0.5.0
editText()
Section titled “editText()”editText( index, run, text, fonts?): EditedJs;Defined in: packages/sdk/src/content.ts:82
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) 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 says so before the edit.
Parameters
Section titled “Parameters”number
TextRunRef
string
fonts?
Section titled “fonts?”readonly string[]
Returns
Section titled “Returns”EditedJs
Throws
Section titled “Throws”LaminaPdfError 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.
0.5.0
hitTest()
Section titled “hitTest()”hitTest(index, at): ObjectRef[];Defined in: packages/sdk/src/content.ts:166
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
Section titled “Parameters”number
| readonly [number, number, number, number]
| readonly [number, number]
Returns
Section titled “Returns”ObjectRef[]
Throws
Section titled “Throws”LaminaPdfError as DocumentContent.objects.
0.5.0
objects()
Section titled “objects()”objects(index): PageObjectJs[];Defined in: packages/sdk/src/content.ts:49
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
Section titled “Parameters”number
Returns
Section titled “Returns”PageObjectJs[]
Throws
Section titled “Throws”LaminaPdfError extract-module-not-loaded, page-index-out-of-range; reading
errors.
0.5.0
pageMarks()
Section titled “pageMarks()”pageMarks(index): PageMarkInfo[];Defined in: packages/sdk/src/content.ts:376
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
Section titled “Parameters”number
Returns
Section titled “Returns”PageMarkInfo[]
Throws
Section titled “Throws”LaminaPdfError page-index-out-of-range; reading errors.
0.7.0
planEditText()
Section titled “planEditText()”planEditText( index, run, text, fonts?): TextEditReport;Defined in: packages/sdk/src/content.ts:94
What DocumentContent.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
Section titled “Parameters”number
TextRunRef
string
fonts?
Section titled “fonts?”readonly string[]
Returns
Section titled “Returns”TextEditReport
Throws
Section titled “Throws”LaminaPdfError as DocumentContent.editText, but nothing is changed.
0.7.0
planReplaceText()
Section titled “planReplaceText()”planReplaceText(edits, fonts?): ReplacementPlanJs[];Defined in: packages/sdk/src/content.ts:120
What DocumentContent.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
Section titled “Parameters”readonly TextReplacement[]
fonts?
Section titled “fonts?”readonly string[]
Returns
Section titled “Returns”ReplacementPlanJs[]
0.8.0
remove()
Section titled “remove()”remove(index, id): EditedJs;Defined in: packages/sdk/src/content.ts:265
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
Section titled “Parameters”number
string
Returns
Section titled “Returns”EditedJs
Throws
Section titled “Throws”LaminaPdfError unknown-content-object; as Document.apply.
0.7.0
replaceText()
Section titled “replaceText()”replaceText(edits, fonts?): EditedJs;Defined in: packages/sdk/src/content.ts:110
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 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 first and send the ones that can.
Parameters
Section titled “Parameters”readonly TextReplacement[]
fonts?
Section titled “fonts?”readonly string[]
Returns
Section titled “Returns”EditedJs
Throws
Section titled “Throws”LaminaPdfError 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.
0.8.0
setAlt()
Section titled “setAlt()”setAlt( index, object, alt): EditedJs;Defined in: packages/sdk/src/content.ts:156
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
Section titled “Parameters”number
object
Section titled “object”ObjectRef
string
Returns
Section titled “Returns”EditedJs
Throws
Section titled “Throws”LaminaPdfError 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.
0.7.0
setHeaderFooter()
Section titled “setHeaderFooter()”setHeaderFooter(pages, headerFooter): EditedJs;Defined in: packages/sdk/src/content.ts:333
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.
doc.content.setHeaderFooter([0, 1, 2], { id: "folio", slots: [null, null, null, null, "Page {page} of {pages}", null], size: 9, modified: "D:20261118120000Z",});Parameters
Section titled “Parameters”readonly number[]
headerFooter
Section titled “headerFooter”Returns
Section titled “Returns”EditedJs
Throws
Section titled “Throws”LaminaPdfError as DocumentContent.addWatermark.
0.7.0
setTextStyle()
Section titled “setTextStyle()”setTextStyle( index, runs, style): EditedJs;Defined in: packages/sdk/src/content.ts:137
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
Section titled “Parameters”number
readonly TextRunRef[]
Returns
Section titled “Returns”EditedJs
Throws
Section titled “Throws”LaminaPdfError 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.
0.7.0
textRuns()
Section titled “textRuns()”textRuns(index): ContentTextRunJs[];Defined in: packages/sdk/src/content.ts:60
The runs of text page index shows, in the order the page draws them: each with its name for
DocumentContent.editText, its text, box, font, size and line and, when it can’t be
edited, why. Text inside a form isn’t listed.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”ContentTextRunJs[]
Throws
Section titled “Throws”LaminaPdfError as DocumentContent.objects.
0.5.0
update()
Section titled “update()”update( index, id, changes): EditedJs;Defined in: packages/sdk/src/content.ts:254
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
Section titled “Parameters”number
string
changes
Section titled “changes”Returns
Section titled “Returns”EditedJs
Throws
Section titled “Throws”LaminaPdfError unknown-content-object, invalid-op (a change for another
kind of object); as DocumentContent.add.
0.7.0
updatePageMark()
Section titled “updatePageMark()”updatePageMark( pages, id, mark, modified): EditedJs;Defined in: packages/sdk/src/content.ts:355
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
Section titled “Parameters”readonly number[]
string
PageMark
modified
Section titled “modified”string
Returns
Section titled “Returns”EditedJs
Throws
Section titled “Throws”LaminaPdfError unknown-page-mark, invalid-op (a mark of another kind); as
DocumentContent.addWatermark.
0.7.0