Adds a custom highlight directly to a specified page.
This method allows you to add a predefined highlight object to a specific page.
// 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);
The index of the page where the highlight should be added (0-based).
The highlight object to add.
Optional args: HighlightBehaviorArgsOptional behavior arguments, such as whether to skip repainting the text layer after adding the highlight.
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.
The start and end indices of the added replace highlight.
The index of the page where the highlight should be added.
The highlight object to add.
Optional args: HighlightBehaviorArgsOptional behavior arguments, such as whether to skip repainting the text layer after adding the highlight.
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.
The start and end indices range of the added replace highlights.
The index of the page where the highlights should be added.
An array of highlight objects to add.
Optional args: HighlightBehaviorArgsOptional behavior arguments, such as whether to skip repainting the text layer after adding the highlights.
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.
// 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 });
Optional args: HighlightBehaviorArgsOptional behavior arguments. If skipPaint is true, the text layer will not be repainted immediately after clearing the highlights.
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.
Optional args: HighlightBehaviorArgsClears 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.
// Clear highlights from page 3:
highlightManager.clearHighlightedSegments(3);
// Clear highlights from pages 1, 4, and 5:
highlightManager.clearHighlightedSegments([1, 4, 5]);
The index of the page or an array of page indices to clear highlights from.
Optional args: HighlightBehaviorArgsRetrieves all highlights for a specified page.
Returns an array of highlight objects present on the given page.
An array of highlights on the specified page.
// Get all highlights from page 2:
const highlights = viewer.getHighlights(2);
The index of the page to retrieve highlights from (0-based).
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.
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.
true if the replace highlight exists, otherwise false.
The index of the page to check.
The unique hash ID of the replace highlight to check.
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.
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)' });
The index of the page where the text segment is located (0-based).
The starting character index (0-based) of the text segment to highlight.
The ending character index (0-based) of the text segment to highlight.
Optional args: { borderColor?: string; borderWidth?: number; clearPrevious?: boolean; color?: string; skipPaint?: boolean }Optional parameters to customize the appearance and behavior of the highlight.
Optional borderThe border color for the highlight in rgba, hex, or named color format.
Optional borderThe width of the highlight border in pixels.
Optional clearIf true, clears existing highlights before adding the new one.
Optional color?: stringThe fill color for the highlight in rgba, hex, or named color format.
Optional skipIf true, skips the immediate repaint of the text layer after adding the highlight.
Removes a specific highlight from a page.
This method removes a highlight at a specified index from the highlights on a given page.
// 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 });
The index of the page from which to remove the highlight (0-based).
The index of the highlight to remove within the specified page.
Optional args: HighlightBehaviorArgsOptional behavior arguments, such as whether to skip repainting the text layer after removing the highlight.
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.
The index of the page where the highlight should be removed.
The index of the highlight in the replaceHighlights array to remove.
Optional args: HighlightBehaviorArgsOptional behavior arguments, such as whether to skip repainting the text layer.
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.
The index of the page where the highlights should be removed.
The range of indices specifying which highlights to remove.
Optional args: HighlightBehaviorArgsOptional behavior arguments, such as whether to skip repainting the text layer.
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.
// Repaint the text layer for page 1:
highlightManager.repaintTextLayer(1);
// Repaint the text layer for pages 2 and 3:
highlightManager.repaintTextLayer([2, 3]);
The index or indices of the pages to repaint.
Interface for managing text highlights within a document. Provides methods to add, remove, retrieve, and clear highlights on specific pages.