The namespace for APIs dealing with document content editing
Extends
Classes
Members
-
<static> Events
-
Properties:
Name Type Description TEXT_CONTENT_UPDATEDstring Core.ContentEdit.textContentUpdated SEARCH_AND_REPLACE_STARTEDstring Core.ContentEdit.searchAndReplaceStarted SEARCH_AND_REPLACE_TEXT_REPLACEDstring Core.ContentEdit.searchAndReplaceTextReplaced SEARCH_AND_REPLACE_TEXT_FOUNDstring Core.ContentEdit.searchAndReplaceTextFound SEARCH_AND_REPLACE_ENDEDstring Core.ContentEdit.searchAndReplaceEnded -
<static> Types
-
Content Edit types.
Properties:
Name Type Description TEXTstring Text type content. OBJECTstring Object type content, currently image only.
Methods
-
<static> addNewParagraph(content, options)
-
Add a new content box.
Parameters:
Name Type Description contentstring The actual text content to be added to the paragraph. optionsObject Configuration for the paragraph, including its position, page number, and styling options. Properties
Name Type Argument Default Description pageNumbernumber <optional>
1 The page number where the paragraph will be inserted. positionObject <optional>
PDF coordinates specifying where the paragraph should appear on the page. Properties
Name Type Argument Default Description topnumber <optional>
130 Distance from the top edge of the page. Needs to be at least 10 higher than position.bottom. leftnumber <optional>
10 Distance from the left edge of the page. rightnumber <optional>
130 Distance from the right edge of the page. Needs to be at least 20 higher than position.left. bottomnumber <optional>
100 Distance from the bottom edge of the page. fontstring <optional>
The font used for the paragraph text. The available fonts can be retrieved from ContentEdit.getContentEditingFonts. fontSizestring <optional>
'12' The font size of the paragraph text. Returns:
A promise that resolves when the content is added.- Type
- Promise.<void>
-
<static> alignContents(contentEditPlaceholderAnnotation, alignment)
-
Align text content
Parameters:
Name Type Description contentEditPlaceholderAnnotationCore.Annotations.Annotation The annotation that represents the content where the text alignment should be set alignmentstring The text alignment to set. Must be one of the following values: 'START', 'CENTER', or 'END'. Returns:
A promise that resolves after the content has been updated- Type
- Promise.<void>
-
<static> getContent(contentEditPlaceholderAnnotation)
-
Gets the content of a content box.
Parameters:
Name Type Description contentEditPlaceholderAnnotationCore.Annotations.RectangleAnnotation The placeholder annotation. See method isContentEditPlaceholder. Returns:
A promise that resolves to the content of the content box- Type
- Promise.<Core.ContentEdit.TextDetails>
-
<static> getContentEditingFonts()
-
Get a list of fonts available for content editing
Returns:
A promise that resolves to a list of fonts available for content editing- Type
- Promise.<Array.<string>>
-
<static> getDocumentContent(contentEditPlaceholderAnnotation)
-
Gets the content box data for the passed in annotation. The passed in annotation must be a content edit placeholder annotation.
Parameters:
Name Type Description contentEditPlaceholderAnnotationCore.Annotations.RectangleAnnotation The content edit placeholder annotation Returns:
A promise that resolves to the document content associated with this content edit placeholder annotation- Type
- Promise.<string>
Example
const content = await instance.Core.ContentEdit.getDocumentContent(contentEditPlaceholderAnnotation);
-
<static> getLongTextReflow()
-
Gets the feature flag that enables / disables the reflow of long text when editing a content box
Returns:
A promise that resolves to a boolean which indicates if long text reflow feature is enabled- Type
- Promise.<boolean>
-
<static> getResourcePath()
-
Get the location of the ContentEdit worker resource file InfixServerWasm.br.mem
Returns:
The URL for InfixServerWasm.br.mem file- Type
- string
-
<static> getWorkerPath()
-
Get the location of the ContentEdit worker files InfixServerModule.js, InfixServerWasm.br.js.mem, InfixServerWasm.br.wasm, and InfixServerWasm.gz.js.mem
Returns:
the URL for InfixServerModule.js, InfixServerWasm.br.js.mem, InfixServerWasm.br.wasm, and InfixServerWasm.gz.js.mem files- Type
- string
-
<static> loadTextAttributes(id, startIndex, selectionLength [, restrictOptions])
-
Load selected text attributes from the Content Edit worker
Parameters:
Name Type Argument Description idstring The ID of the content box, the OID currently startIndexnumber The index where the change starts selectionLengthnumber The length from start index to end index of the selected text restrictOptionsobject <optional>
An object that sets whether font name or font size should be returned Properties
Name Type Argument Description fontNameboolean <optional>
Font name is not returned when restrictFontName is true fontSizeboolean <optional>
Font size is not returned when restrictFontSize is true Returns:
A promise that resolves when the text attributes are loaded- Type
- Promise.<void>
-
<static> preloadWorker(contentEditManager)
-
Preloads the content editing worker. If this function isn't called then the worker will be loaded when the content editing tool is enabled.
Parameters:
Name Type Description contentEditManagerCore.ContentEditManager The ContentEditManager to use as context for the page editing Returns:
A promise that resolves after the worker has been loaded- Type
- Promise.<void>
-
<static> regeneratePage()
-
Sends a command to the worker to regenerate the content boxes and page content.
Returns:
Resolves after the page is prepared for editing- Type
- Promise.<void>
-
<static> searchAndReplaceText(options)
-
A function that will search and replace text inside the document.
Parameters:
Name Type Description optionsobject Properties
Name Type Argument Description toReplacestring | RegExp A string or global RegExp object that will be replaced on the page. replaceWithstring The string that replaces the string or RegExp provided in the first parameter. documentViewerCore.DocumentViewer DocumentViewer instance. searchResultsArray.<Core.Search.SearchResult> The array of search results. caseSensitiveboolean <optional>
Whether the search is case sensitive. wholeWordboolean <optional>
Whether to search for the whole word. wildcardboolean <optional>
Whether to search with wildcard. regexboolean <optional>
Whether to search with regular expression. isSingleSearchReplaceboolean <optional>
Whether it is single search and replace or whole document. Returns:
A promise that resolves when the operation completes.- Type
- Promise.<void>
Example
instance.Core.ContentEdit.searchAndReplaceText({ toReplace: 'PDF', replaceWith: 'DOCX', documentViewer: instance.Core.documentViewer, searchResults: instance.Core.documentViewer.getPageSearchResults([1]) }); -
<static> setContent(contentEditPlaceholderAnnotation, content [, isInheritingContentBoxStyles])
-
Sets the content of a content box.
Parameters:
Name Type Argument Default Description contentEditPlaceholderAnnotationCore.Annotations.RectangleAnnotation The placeholder annotation. See method isContentEditPlaceholder. contentstring | Array.<Core.ContentEdit.SpanObject> The content to update. When using an XML string, it should be in the same format of the string that you obtain from getContent(annot), that is, a string where one or multiple elements wrapping the elements.
isInheritingContentBoxStylesboolean <optional>
true Flag that specifies if the font size and font family from the content box will be applied Returns:
A promise that resolves when the content is set- Type
- Promise.<void>
Example
const annot = instance.Core.annotationManager.getSelectedAnnotations()[0]; const str = `<p><span style = "font-family: Lato;font-size: 12px; color: #424242; align: Start; leading-mode: Auto; leading: 1.33; start-indent: 0.00;">You plan to embed PDF functionality into an application.</span></p>`; await instance.Core.ContentEdit.setContent(annot, str, true);
-
<static> setContentFont(contentEditPlaceholderAnnotation, font)
-
Set font of text content
Parameters:
Name Type Description contentEditPlaceholderAnnotationCore.Annotations.Annotation The annotation that represents the content where the font should be set fontstring The font family to set Returns:
A promise that resolves after the content has been updated- Type
- Promise.<void>
-
<static> setContentFontSize(contentEditPlaceholderAnnotation, size)
-
Set font size of text content
Parameters:
Name Type Description contentEditPlaceholderAnnotationCore.Annotations.Annotation The annotation that represents the content where font size should be set sizestring The font size to set Returns:
A promise that resolves after the content has been updated- Type
- Promise.<void>
-
<static> setLongTextReflow(contentEditManager, textReflow)
-
Sets the feature flag that enables / disables the reflow of long text when editing a content box
Parameters:
Name Type Description contentEditManagerCore.ContentEditManager The ContentEditManager instance textReflowboolean A boolean that specifies if the long text reflow feature should be enabled Returns:
A promise that resolves when the feature flag is set- Type
- Promise.<void>
-
<static> setResourcePath(workerPath)
-
Set the location of the ContentEdit worker resource file InfixServerWasm.br.mem This will override the location specified by Core.setWorkerPath for InfixServerWasm.br.mem file.
Parameters:
Name Type Description workerPathstring The URL for InfixServerWasm.br.mem file -
<static> setTextAttributes(attributes)
-
Sets the active text attributes to be applied to new text
Parameters:
Name Type Description attributesCore.ContentEdit.TextAttributes The attributes to set Returns:
A promise that resolves when the text attributes are set- Type
- Promise.<void>
-
<static> setTextColor(contentEditPlaceholderAnnotation, color)
-
Set font color of text content
Parameters:
Name Type Description contentEditPlaceholderAnnotationCore.Annotations.Annotation The annotation that represents the content where the text color should be set colorstring The color of the text to set Returns:
A promise that resolves after the content has been updated- Type
- Promise.<void>
-
<static> setWorkerPath(workerPath)
-
Set the location of the ContentEdit workers for InfixServerModule.js, InfixServerWasm.br.js.mem, InfixServerWasm.br.wasm, and InfixServerWasm.gz.js.mem files. This will override the location specified by Core.setWorkerPath for ContentEdit worker files.
Parameters:
Name Type Description workerPathstring The URL for InfixServerModule.js, InfixServerWasm.br.js.mem, InfixServerWasm.br.wasm, and InfixServerWasm.gz.js.mem files -
<static> toggleBoldContents(contentEditPlaceholderAnnotation)
-
Bold or unbold text content
Parameters:
Name Type Description contentEditPlaceholderAnnotationCore.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>
-
<static> toggleItalicContents(contentEditPlaceholderAnnotation)
-
Italicize or unitalicize text content
Parameters:
Name Type Description contentEditPlaceholderAnnotationCore.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>
-
<static> toggleStrikeContents(contentEditPlaceholderAnnotation)
-
Strike or de-strike text content
Parameters:
Name Type Description contentEditPlaceholderAnnotationCore.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>
-
<static> toggleUnderlineContents(contentEditPlaceholderAnnotation)
-
Underline or de-underline text content
Parameters:
Name Type Description contentEditPlaceholderAnnotationCore.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>
-
<static> updateDocumentContent(contentEditPlaceholderAnnotation, content [, isInheritingContentBoxStyles])
-
Update the document with new content
Parameters:
Name Type Argument Default Description contentEditPlaceholderAnnotationCore.Annotations.RectangleAnnotation The content edit placeholder annotation contentstring The new content isInheritingContentBoxStylesboolean <optional>
true A flag that specifies if the font size and font family from the content box will be applied Returns:
A promise that resolves after the content has been updated- Type
- Promise.<void>
Example
instance.Core.ContentEdit.updateDocumentContent(contentEditPlaceholderAnnotation, 'New content');
-
addEventListener(type, fn [, options])
-
Add a handler to the given event name
Parameters:
Name Type Argument Description typestring | number The name of the event to listen to fnfunction The handler to be called when the event is triggered optionsobject <optional>
Optional options object for addEventListener Properties
Name Type Description onceboolean If true then the handler will be called only once Returns:
Returns the object that 'addEventListener' is being called on- Type
- object
Example
Core.ContentEdit.addEventListener('textContentUpdated', (originalText, updatedText, boundingBoxCoordinates) => { ... }); -
removeEventListener( [type] [, fn])
-
Remove a handler of the given event name and namespace (if given) or with a function reference
Parameters:
Name Type Argument Description typestring | number <optional>
The name of the event to remove the handler of with an optional namespace. fnfunction <optional>
The handler associated with this event to be removed. If fn is undefined, all the handlers of the given event namespace will be removed If you are not passing in this parameter then a namespace must be used with the event name. Returns:
Returns the object that 'removeEventListener' is being called on- Type
- object
Example
Core.ContentEdit.removeEventListener('textContentUpdated.namespace'); Core.ContentEdit.removeEventListener('textContentUpdated', fn); -
trigger(type [, data])
-
Calls the handlers of the event name with given data
Parameters:
Name Type Argument Description typestring | number event name of which the handlers will be called. data* <optional>
data that will be passed to the handlers. If data is an array, it will be spread and then passed to the handlers Returns:
Returns the object that 'trigger' is being called on- Type
- object
Example
Core.ContentEdit.trigger('textContentUpdated', originalText, updatedText, boundingBoxCoordinates);
Type Definitions
-
ObjectBox
-
Object box data containing PDF object information and positioning
Type:
- Object
Properties:
Name Type Description oidstring The PDF object ID pagenumnumber The page number where the object is located typestring The type of the PDF object (e.g., "Image") -
SpanObject
-
Properties:
Name Type Argument Description textstring The text content of the span. paragraphIndexnumber The index of the paragraph this span belongs to. fontFamilystring <optional>
The font family of the text. fontWeightstring <optional>
The font weight of the text. fontSizestring <optional>
The font size of the text. fontStylestring <optional>
The font style of the text. colorstring <optional>
The color of the text. alignstring <optional>
The text alignment. leadingModestring <optional>
The line height or leading mode of the text. startIndentstring <optional>
The text indent. underlineStartnumber <optional>
The start position of the underline if applicable. underlineEndnumber <optional>
The end position of the underline if applicable. -
TextAttributes
-
TextAttributes types.
Properties:
Name Type Description boldStylesArray.<Object> Array of objects representing bold styles and their character counts. boldStyles[].boldboolean Bold style value. boldStyles[].characterCountnumber Character count for the bold style. fontColorsArray.<Object> Array of objects representing font colors, their character counts, and color indices. fontColors[].fontColorstring Font color value. fontColors[].characterCountnumber Character count for the font color. fontColors[].colorIndexnumber Color index value. fontNamesArray.<Object> Array of objects representing font names and their character counts. fontNames[].fontNamestring Font name value. fontNames[].characterCountnumber Character count for the font name. fontSizesArray.<Object> Array of objects representing font sizes and their character counts. fontSizes[].fontSizestring Font size value. fontSizes[].characterCountnumber Character count for the font size. italicStylesArray.<Object> Array of objects representing italic styles and their character counts. italicStyles[].italicboolean Italic style value. italicStyles[].characterCountnumber Character count for the italic style. underlineStylesArray.<Object> Array of objects representing underline styles and their character counts. underlineStyles[].underlineboolean Underline style value. underlineStyles[].characterCountnumber Character count for the underline style. leadingsArray.<Object> Array of objects representing leadings. leadings[].leadingnumber Leading value. textAlignsArray.<Object> Array of objects representing text alignments. textAligns[].textAlignstring Text alignment value. boldboolean Indicates whether the text is bold. fontColorstring The color of the font. fontNamestring The name of the font. fontSizestring The size of the font. italicboolean Indicates whether the text is italicized. leadingnumber The leading (line spacing) value. textAlignstring The text alignment (e.g., left, right, center). underlineboolean Indicates whether the text is underlined. strikeboolean Indicates whether the text has a strikethrough. valignstring The vertical alignment of the text. autofitboolean Indicates whether the text should automatically fit within its container. -
TextBox
-
Text box data object containing text content and positioning information
Type:
- Object
Properties:
Name Type Description oidstring The PDF object ID contentsstring The text contents of the text box idstring The unique identifier for the text box pagenumnumber The page number where the text box is located -
TextDetails
-
Properties:
Name Type Description xmlStringstring The text details presented in XML string. spanObjectsCore.ContentEdit.SpanObject The text details presented in an array of SpanObjects.
Events
-
editBoxesAvailable
-
Triggered any time edit boxes are drawn on the page.
Parameters:
Name Type Description boxesobject An array of Content Edit boxes. -
textContentUpdated
-
Triggered when text content of the page is updated.
Parameters:
Name Type Description originalTextstring The original text of the selected bounding box. updatedTextstring The updated text of the selected bounding box. boundingBoxCoordinatesCore.Math.Rect The coordinates (top, left, bottom, right) of the bounding box. -
undoRedoStatusChanged
-
Triggers when the undo redo status is changed. Can be used together with contentEditHistoryManager.undo or contentEditHistoryManager.redo
Example
Core.ContentEdit.addEventListener('undoRedoStatusChanged', () => { console.log('can undo?', contentEditHistoryManager.canUndo()) console.log('can redo?', contentEditHistoryManager.canRedo()) });