[]
Interface for managing text highlights within a document. Provides methods to add, remove, retrieve, and clear highlights on specific pages.
addHighlight(
pageIndex,
highlight,
args?): number;
Adds a custom highlight directly to a specified page.
This method allows you to add a predefined highlight object to a specific page.
number
The index of the page where the highlight should be added (0-based).
The highlight object to add.
Optional behavior arguments, such as whether to skip repainting the text layer after adding the highlight.
number
// Add a custom highlight to page 1:
const highlight = { rects: [{ x: 10, y: 20, w: 100, h: 15 }], color: 'rgba(0, 255, 0, 0.3)' };
highlightManager.addHighlight(1, highlight);
addReplaceHighlight(
pageIndex,
highlight,
args?): object;
Adds a replace text highlight to the specified page's replaced highlights map.
Replace highlights are used internally by the viewer to display replaced text segments
(e.g., during text comparison or editing operations). For most use cases, regular
highlights (addHighlight) or custom highlights are more appropriate.
number
The index of the page where the highlight should be added.
The highlight object to add.
Optional behavior arguments, such as whether to skip repainting the text layer after adding the highlight.
object
The start and end indices of the added replace highlight.
end: number;
start: number;
addReplaceHighlights(
pageIndex,
highlights,
args?): object;
Adds multiple replace text highlights to the specified page's replaced highlights map.
Replace highlights are used internally by the viewer to display replaced text segments
(e.g., during text comparison or editing operations). For most use cases, regular
highlights (addHighlight) or custom highlights are more appropriate.
number
The index of the page where the highlights should be added.
An array of highlight objects to add.
Optional behavior arguments, such as whether to skip repainting the text layer after adding the highlights.
object
The start and end indices range of the added replace highlights.
end: number;
start: number;
cleanupDocument(): void;
Cleans up the document by resetting the highlights and replaced highlights. This method clears all current highlights and replaced highlights, effectively preparing the document for a new state or fresh rendering.
void
clearAllHighlights(args?): void;
Clears all highlights from all pages in the document.
This method removes all custom highlights from every page in the document. You can optionally control whether to skip repainting the text layer after clearing the highlights.
Optional behavior arguments. If skipPaint is true, the text layer will not be repainted immediately after clearing the highlights.
void
// Clear all highlights from the entire document and repaint the text layer:
highlightManager.clearAllHighlights();
// Clear all highlights from the entire document and skip repainting:
highlightManager.clearAllHighlights({ skipPaint: true });
clearAllReplaceHighlights(args?): void;
Clears all replaced highlights for a specified page.
Replace highlights are used internally by the viewer to display replaced text segments.
For clearing regular highlights, use clearHighlightedSegments or clearAllHighlights instead.
void
clearHighlightedSegments(pageIndex, args?): void;
Clears all highlights from one or more specific pages.
Removes all custom highlights from the specified pages. You can pass either a single page index or an array of page indices.
The index of the page or an array of page indices to clear highlights from.
number | number[]
void
// Clear highlights from page 3:
highlightManager.clearHighlightedSegments(3);
// Clear highlights from pages 1, 4, and 5:
highlightManager.clearHighlightedSegments([1, 4, 5]);
getHighlightsForPage(pageIndex): ICustomHighlight[];
Retrieves all highlights for a specified page.
Returns an array of highlight objects present on the given page.
number
The index of the page to retrieve highlights from (0-based).
An array of highlights on the specified page.
// Get all highlights from page 2:
const highlights = viewer.getHighlights(2);
getReplaceTextData(): ReplaceTextModel[];
Retrieves an array of ReplaceTextModel data from the replaced highlights.
This method iterates over the replaceHighlights map, collects the replaceData
from each highlight, and returns it in an array.
An array of ReplaceTextModel objects,
or undefined if no replace highlights are found.
hasReplaceHighlight(pageIndex, hashId): boolean;
Checks if a replace highlight exists for the given page and hash ID.
Replace highlights are used internally by the viewer to display replaced text segments.
For checking regular highlights, use getHighlightsForPage instead.
number
The index of the page to check.
string
The unique hash ID of the replace highlight to check.
boolean
true if the replace highlight exists, otherwise false.
highlightTextSegment(
pageIndex,
startCharIndex,
endCharIndex,
args?): Promise<boolean>;
Highlights a specified segment of text on a given page.
This method allows you to highlight a portion of text by specifying the start and end character indices. The appearance of the highlight can be customized using the optional parameters.
number
The index of the page where the text segment is located (0-based).
number
The starting character index (0-based) of the text segment to highlight.
number
The ending character index (0-based) of the text segment to highlight.
Optional parameters to customize the appearance and behavior of the highlight.
string
The border color for the highlight in rgba, hex, or named color format.
number
The width of the highlight border in pixels.
boolean
If true, clears existing highlights before adding the new one.
string
The fill color for the highlight in rgba, hex, or named color format.
boolean
If true, skips the immediate repaint of the text layer after adding the highlight.
Promise<boolean>
A promise that resolves once the highlight has been added.
// Highlight text on page 2 from character index 10 to 20 with a yellow background:
highlightManager.highlightTextSegment(2, 10, 20, { color: 'rgba(255, 255, 0, 0.5)' });
removeHighlight(
pageIndex,
index,
args?): void;
Removes a specific highlight from a page.
This method removes a highlight at a specified index from the highlights on a given page.
number
The index of the page from which to remove the highlight (0-based).
number
The index of the highlight to remove within the specified page.
Optional behavior arguments, such as whether to skip repainting the text layer after removing the highlight.
void
// Remove the first highlight from page 2:
viewer.removeHighlight(2, 0);
// Remove the second highlight from page 1 and skip repainting:
viewer.removeHighlight(1, 1, { skipPaint: true });
removeReplaceHighlight(
pageIndex,
index,
args?): void;
Removes a replace highlight from the specified page's replaced highlights map by its index.
Replace highlights are used internally by the viewer to display replaced text segments.
For regular highlight management, use removeHighlight instead.
number
The index of the page where the highlight should be removed.
number
The index of the highlight in the replaceHighlights array to remove.
Optional behavior arguments, such as whether to skip repainting the text layer.
void
removeReplaceHighlights(
pageIndex,
indices,
args?): void;
Removes replace highlights from the specified page's replaced highlights map by their index range.
Replace highlights are used internally by the viewer to display replaced text segments.
For regular highlight management, use removeHighlight instead.
number
The index of the page where the highlights should be removed.
The range of indices specifying which highlights to remove.
number
number
Optional behavior arguments, such as whether to skip repainting the text layer.
void
repaintTextLayer(pageIndices): void;
Repaints the text layer for one or more specified pages.
This method updates the display of highlights by repainting the text layer on the specified pages.
The index or indices of the pages to repaint.
number | number[]
void
// Repaint the text layer for page 1:
highlightManager.repaintTextLayer(1);
// Repaint the text layer for pages 2 and 3:
highlightManager.repaintTextLayer([2, 3]);