Class: ContentEditManager

Core. ContentEditManager

A manager class that controls document content editing.

new ContentEditManager(documentViewer)

Parameters:
Name Type Description
documentViewer Core.DocumentViewer

Extends

  • EventHandler

Members


<static> Events

Properties:
Name Type Description
CONTENT_EDIT_STARTED string Core.ContentEditManager.contentEditModeStarted
CONTENT_EDIT_ENDED string Core.ContentEditManager.contentEditModeEnded
CONTENT_BOX_EDIT_STARTED string Core.ContentEditManager.contentBoxEditStarted
CONTENT_BOX_EDIT_ENDED string Core.ContentEditManager.contentBoxEditEnded
CONTENT_BOX_ADDED string Core.ContentEditManager.contentBoxAdded
CONTENT_BOX_DELETED string Core.ContentEditManager.contentBoxDeleted
CONTENT_BOX_SELECTION_CHANGE string Core.ContentEditManager.contentEditSelectionChange
CONTENT_EDIT_DOCUMENT_DIGITALLY_SIGNED string Core.ContentEditManager.contentEditDocumentDigitallySigned
CONTENT_EDIT_PASSWORD_REQUIRED string Core.ContentEditManager.contentEditPasswordRequired
EDIT_BOXES_AVAILABLE string Core.ContentEditManager.editBoxesAvailable
TEXT_CONTENT_UPDATED string Core.ContentEditManager.textContentUpdated
SEARCH_AND_REPLACE_STARTED string Core.ContentEditManager.searchAndReplaceStarted
SEARCH_AND_REPLACE_TEXT_FOUND string Core.ContentEditManager.searchAndReplaceTextFound
SEARCH_AND_REPLACE_TEXT_REPLACED string Core.ContentEditManager.searchAndReplaceTextReplaced
SEARCH_AND_REPLACE_ENDED string Core.ContentEditManager.searchAndReplaceEnded
UNDO_REDO_STATUS_CHANGED string Core.ContentEditManager.undoRedoStatusChanged

Methods


addImage(annotation)

Inserts a new image into the document using a placeholder.
Parameters:
Name Type Description
annotation Core.Annotations.Annotation The annotation representing the content edit placeholder for the image.
Returns:
Type
Promise.<void>

addImage(pageNumber, rect, image [, options])

Inserts a new image into the document.
Parameters:
Name Type Argument Description
pageNumber number The page number to insert the image on.
rect Core.ContentEdit.BoundingBox The bounding box in PDF coordinates defining position and size.
image string | ArrayBuffer The image data as a base64 data URL string or an ArrayBuffer.
options Core.ContentEdit.AddImageOptions <optional>
Optional image settings.
Returns:
Type
Promise.<void>

addParagraph(annotation, content, isAddingHTMLContent)

Adds a new textbox to the document using a placeholder annotation.
Parameters:
Name Type Description
annotation Core.Annotations.Annotation The annotation containing the data and properties to add
content string The text content to add
isAddingHTMLContent boolean If the text content to add is HTML
Returns:
Type
Promise.<void>

addParagraph(pageNumber, rect, content [, options])

Adds a new textbox to the document.
Parameters:
Name Type Argument Description
pageNumber number The page number to insert the paragraph on.
rect Core.ContentEdit.BoundingBox The bounding box in PDF coordinates defining position and size.
content string The text content to add.
options Core.ContentEdit.AddParagraphOptions <optional>
Optional font and content format settings.
Returns:
Type
Promise.<void>

alignContents(contentEditPlaceholderAnnotation, alignment)

Aligns text content for a content edit placeholder. When the content box is being edited, the alignment is applied to the current selection. When not editing, the alignment is applied to the entire content box.
Parameters:
Name Type Description
contentEditPlaceholderAnnotation Core.Annotations.Annotation The annotation that represents the content where alignment should be set.
alignment 'Left' | 'Start' | 'Center' | 'End' | 'Justify' | 'JustifyAll' | 'JustifyRight' The paragraph alignment to apply.
Returns:
A promise that resolves after alignment is applied.
Type
Promise.<void>

bringBackward( [contentBoxId])

Moves the content box with the given ID one step backward in the z-order on its page. Falls back to the currently selected annotation's content box if no ID is provided.
Parameters:
Name Type Argument Description
contentBoxId string <optional>
The ID of the content box to bring backward.
Returns:
A promise that resolves when the command has been sent and the page regenerated.
Type
Promise.<void>

bringForward( [contentBoxId])

Moves the content box with the given ID one step forward in the z-order on its page. Falls back to the currently selected annotation's content box if no ID is provided.
Parameters:
Name Type Argument Description
contentBoxId string <optional>
The ID of the content box to bring forward.
Returns:
A promise that resolves when the command has been sent and the page regenerated.
Type
Promise.<void>

calculateDefaultCursorPosition(contentBoxText)

Calculates the cursor index based on the current default cursor position.
Parameters:
Name Type Description
contentBoxText Array.<Core.ContentEditManager.TextLineData> The text lines in the content box.
Returns:
The index of the initial cursor position.
Type
number

endContentEditMode( [options])

Ends the Content Edit mode and removes content edit boxes from the document.
Parameters:
Name Type Argument Description
options Core.ContentEditManager.EndContentEditModeOptions <optional>
Options for ending Content Edit mode.
Returns:
A promise that resolves when Content Edit mode is ended and the document is updated.
Type
Promise.<void>

getActiveEditingContentBox()

Gets the currently active content box being edited.
Returns:
The active content box, or null if none is active
Type
Core.ContentEdit.ContentBox | null

getContent(contentEditPlaceholderAnnotation)

Gets the content of a text content box in both XML string and span-object formats.
Parameters:
Name Type Description
contentEditPlaceholderAnnotation Core.Annotations.Annotation The content edit placeholder annotation.
Returns:
The text content as XML and span objects.
Type
Promise.<Core.ContentEdit.TextDetails>

getContentBoxAttributes(contentBoxId)

Gets the text attributes applied to a content box.
Parameters:
Name Type Description
contentBoxId string The ID of the content box.
Returns:
The content box text attributes.
Type
Promise.<Core.ContentEdit.TextAttributes>

getContentBoxById(id)

Gets a content box instance by its ID.
Parameters:
Name Type Description
id string The content box ID.
Returns:
The content box, or undefined if it is not registered.
Type
Core.ContentEdit.ContentBox | undefined

getDefaultCursorPosition()

Gets the configured initial caret position for content-box editing.
Returns:
The initial caret position.
Type
'start' | 'end'

getFontFamilyCatalog()

Retrieves the cached font catalog.
Returns:
The font catalog, or null if it has not been set.
Type
Array.<string> | null

hasActiveContentBoxEditor()

Returns if there is an active editor for a content box.
Returns:
True if there is an active editor, false otherwise.
Type
boolean

isContentBoxEditorActive(arg)

Check if the given content box or placeholder annotation is the active editing content box.
Parameters:
Name Type Description
arg Core.Annotations.Annotation | Core.ContentEdit.ContentBox placeholder annotation or content box to check
Returns:
True if the given content box or placeholder annotation is the active editing content box, false otherwise.
Type
boolean

isInContentEditMode()

Gets if the Content Edit manager is currently in content edit mode
Returns:
True if currently in content edit mode, false otherwise
Type
boolean

isReplacingText()

Gets whether a text replace operation is currently running. This is true from the moment replaceText begins until it finishes, including when it fails. Use it to suppress work that should not run against a document that is mid-replace, such as reacting to the content changes the replace itself causes.
Returns:
True if a replace is in progress, false otherwise
Type
boolean

isShowingInvisibleCharacters()

Returns whether invisible characters are currently included in content edit renders. The value is manager-scoped and persists across content edit mode stop/start.
Returns:
True if invisible characters are shown.
Type
boolean

isToolAllowedInContentEditMode(toolName)

Returns whether or not a tool is allowed to be used in content edit mode.
Parameters:
Name Type Description
toolName string The name of the tool to check.
Returns:
Whether the tool is allowed in Content Edit mode.
Type
boolean

redo()

Reapplies the most recently undone Content Edit operation.
Returns:
A promise that resolves when the redo operation and its updates are complete.
Type
Promise.<void>

replaceText(searchResults, replacement [, options])

Replaces text based on search results. Get the search results from DocumentViewer.search() and pass them to this method along with the replacement text. The method will handle replacing the text in the document and updating the search results accordingly.
Parameters:
Name Type Argument Description
searchResults Array.<Core.Search.SearchResult> Array of search results from DocumentViewer.search()
replacement string The replacement text
options Core.ContentEdit.ReplaceOptions <optional>
Optional replacement behavior.
Properties
Name Type Argument Default Description
caseSensitive boolean <optional>
false If true, match text case-sensitively.
wholeWord boolean <optional>
false If true, match whole words only.
resultIndexInPage number <optional>
Precomputed page-local index for single-result replace.
Returns:
A promise that resolves when the replacement operation is complete
Type
Promise.<void>

sendToBack( [contentBoxId])

Moves the content box with the given ID to the back of the z-order on its page. Falls back to the currently selected annotation's content box if no ID is provided.
Parameters:
Name Type Argument Description
contentBoxId string <optional>
The ID of the content box to send to the back.
Returns:
A promise that resolves when the command has been sent and the page regenerated.
Type
Promise.<void>

sendToFront( [contentBoxId])

Moves the content box with the given ID to the front of the z-order on its page. Falls back to the currently selected annotation's content box if no ID is provided.
Parameters:
Name Type Argument Description
contentBoxId string <optional>
The ID of the content box to bring to the front.
Returns:
A promise that resolves when the command has been sent and the page regenerated.
Type
Promise.<void>

setContent(contentEditPlaceholderAnnotation, content [, isInheritingContentBoxStyles])

Sets the content of a text content box using an XML string or span objects.
Parameters:
Name Type Argument Default Description
contentEditPlaceholderAnnotation Core.Annotations.Annotation The content edit placeholder annotation.
content string | Array.<Core.ContentEdit.SpanObject> New content to apply.
isInheritingContentBoxStyles boolean <optional>
true Whether to preserve content-box base styles.
Returns:
A promise that resolves after the content is updated.
Type
Promise.<void>

setContentBoxAttributes(attributes, contentBox)

Sets the text attributes applied to the content edit box.
Parameters:
Name Type Description
attributes Core.ContentEdit.TextAttributes The text attributes to apply to the content box.
contentBox Core.ContentEdit.ContentBox The content box to update.

setDefaultCursorPosition(cursorPosition)

Sets whether the initial caret is placed at the start or end of a content box.
Parameters:
Name Type Description
cursorPosition 'start' | 'end' The initial caret position.

setTextColor(contentEditPlaceholderAnnotation, color)

Sets text color for a content edit placeholder. When the content box is being edited, the color is applied to the current selection or caret position. When not editing, the color is applied to the entire content box.
Parameters:
Name Type Description
contentEditPlaceholderAnnotation Core.Annotations.Annotation The annotation that represents the content where text color should be set.
color string The hex color to apply.
Returns:
A promise that resolves after the color is applied.
Type
Promise.<void>

startContentEditMode()

Starts the Content Edit mode, a mode in which links are disabled and boxes are drawn around all editable content so users can edit them.
Returns:
A promise that resolves when Content Edit mode is started.
Type
Promise.<void>

startEditingContentBox(target)

Starts editing a content box by annotation or a content box ID.
Parameters:
Name Type Description
target Core.Annotations.Annotation | string The content edit placeholder or content box ID string identifying the box to edit.
Returns:
A promise that resolves when the content box has been rendered and the edit session is ready.
Type
Promise.<void>
Examples
// Edit by annotation
await contentEditManager.startEditingContentBox(annotation);
// Edit by content box ID string
await contentEditManager.startEditingContentBox('content-box-123');

stopEditingContentBox(target)

Stops the active editing session for a text content box.
Parameters:
Name Type Description
target Core.Annotations.Annotation | string The content-edit placeholder annotation or content box ID.
Returns:
A promise that resolves when editing stops.
Type
Promise.<void>

toggleBoldContents(contentEditPlaceholderAnnotation)

Bold or unbold text content (v4).
Parameters:
Name Type Description
contentEditPlaceholderAnnotation Core.Annotations.Annotation The annotation that represents the content where bold should be toggled
Returns:
A promise that resolves after the content has been updated
Type
Promise.<void>

toggleInvisibleCharacters()

Toggles the visibility of invisible characters in the content edit boxes.

toggleItalicContents(contentEditPlaceholderAnnotation)

Italicize or unitalicize text content (v4).
Parameters:
Name Type Description
contentEditPlaceholderAnnotation Core.Annotations.Annotation The annotation that represents the content where italics should be toggled
Returns:
A promise that resolves after the content has been updated
Type
Promise.<void>

toggleStrikeContents(contentEditPlaceholderAnnotation)

Strike or de-strike text content (v4).
Parameters:
Name Type Description
contentEditPlaceholderAnnotation Core.Annotations.Annotation The annotation that represents the content where strike should be toggled
Returns:
A promise that resolves after the content has been updated
Type
Promise.<void>

toggleUnderlineContents(contentEditPlaceholderAnnotation)

Underline or de-underline text content (v4).
Parameters:
Name Type Description
contentEditPlaceholderAnnotation Core.Annotations.Annotation The annotation that represents the content where underline should be toggled
Returns:
A promise that resolves after the content has been updated
Type
Promise.<void>

undo()

Undoes the most recent Content Edit operation.
Returns:
A promise that resolves when the undo operation and its updates are complete.
Type
Promise.<void>

Type Definitions


ContentBoxEditStartedEvent

Payload emitted when a content box enters editing mode.
Type:
  • object
Properties:
Name Type Description
editor Core.ContentEdit.ContentEditSession | null The active editing session, or null if unavailable.
annotation Core.Annotations.Annotation The content-box placeholder annotation.

ContentBoxEventData

Information about a content box added to or deleted from the document.
Type:
  • object
Properties:
Name Type Description
id string The content box ID.
type string The content box type, such as text or object.
pageNumber number The page containing the content box.
position Core.ContentEdit.BoundingBox | null The content box bounds in PDF coordinates, or null if unavailable.
data string | ArrayBuffer | Core.ContentEditManager.EmptyContentBoxData | null The text content or image data. For a deleted object box, this is an empty object.

ContentEditSelectionChangeEvent

Details emitted when the selection in the active content box changes.
Type:
  • object
Properties:
Name Type Description
event Event The underlying selection event.

CursorCharacter

Character data used in a text line for cursor-position calculation.
Type:
  • object
Properties:
Name Type Description
character string The character value.

EmptyContentBoxData

Empty payload used when a deleted object box has no content data.
Type:
  • object

EndContentEditModeOptions

Options for ending Content Edit mode through the manager API.
Type:
  • object
Properties:
Name Type Argument Description
keepReloadHandler boolean <optional>
Whether to keep the document reload handler registered.
dispose boolean <optional>
Whether to dispose the manager and its resources after ending Content Edit mode.

TextContentUpdatedEvent

Details emitted when the text content of a content box changes.
Type:
  • object
Properties:
Name Type Description
oldContent string The content before the update.
newContent string The content after the update.
coords Core.Math.Rect The content box bounds in viewer coordinates.

TextLineData

Text-line data used by calculateDefaultCursorPosition.
Type:
  • object
Properties:
Name Type Description
chars Array.<Core.ContentEditManager.CursorCharacter> Characters on the line.

Events


contentBoxAdded

Triggered when a content box is added, including when it is restored by redo.
Parameters:
Name Type Description
contentBox Core.ContentEditManager.ContentBoxEventData Information about the added content box.

contentBoxDeleted

Triggered when a content box is deleted, including when it is removed by undo.
Parameters:
Name Type Description
contentBox Core.ContentEditManager.ContentBoxEventData Information about the deleted content box.

contentBoxEditEnded

Triggered when editing of a content box ends.

contentBoxEditStarted

Triggered when a content box enters editing mode.
Parameters:
Name Type Description
event Core.ContentEditManager.ContentBoxEditStartedEvent The active editor and its placeholder annotation.

contentEditDocumentDigitallySigned

Triggered when a digitally signed document cannot enter Content Edit mode.

contentEditModeEnded

Triggered when Content Edit mode ends.

contentEditModeStarted

Triggered when Content Edit mode starts.

contentEditPasswordRequired

Triggered when a password is required to enter Content Edit mode.
Parameters:
Name Type Description
passwordCheckCallback function Checks a password and resolves to whether it is valid.
successCallback function Starts Content Edit mode after the password has been accepted.

contentEditSelectionChange

Triggered when the selection in the active content box changes.
Parameters:
Name Type Description
selectionChange Core.ContentEditManager.ContentEditSelectionChangeEvent The selection-change event details.

editBoxesAvailable

Triggered when editable content boxes have been loaded for a page.
Parameters:
Name Type Description
contentBoxes Array.<(Core.ContentEdit.TextBox|Core.ContentEdit.ObjectBox)> The loaded text and object content-box data for the page.

searchAndReplaceEnded

Triggered when a search-and-replace operation finishes, whether or not any text was replaced.

searchAndReplaceStarted

Triggered when a search-and-replace operation starts.

searchAndReplaceTextFound

Triggered when a search-and-replace operation finds matches.
Parameters:
Name Type Description
searchResults Array.<Core.Search.SearchResult> The search results found by the operation.

searchAndReplaceTextReplaced

Triggered when a search-and-replace operation replaces at least one match.

textContentUpdated

Triggered when the text content of a content box changes.
Parameters:
Name Type Description
update Core.ContentEditManager.TextContentUpdatedEvent The content update details.

undoRedoStatusChanged

Triggered when the available undo or redo state changes.