[]
        
(Showing Draft Content)

IHighlightManager

Interface: IHighlightManager

Interface for managing text highlights within a document. Provides methods to add, remove, retrieve, and clear highlights on specific pages.

Methods

addHighlight()

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.

Parameters

pageIndex

number

The index of the page where the highlight should be added (0-based).

highlight

ICustomHighlight

The highlight object to add.

args?

HighlightBehaviorArgs

Optional behavior arguments, such as whether to skip repainting the text layer after adding the highlight.

Returns

number

Example

// 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()

addReplaceHighlight(
   pageIndex, 
   highlight, 
   args?): object;

Adds a replace text highlight to the specified page's replaced highlights map.

Note for Users

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.

Parameters

pageIndex

number

The index of the page where the highlight should be added.

highlight

ICustomHighlight

The highlight object to add.

args?

HighlightBehaviorArgs

Optional behavior arguments, such as whether to skip repainting the text layer after adding the highlight.

Returns

object

The start and end indices of the added replace highlight.

end
end: number;
start
start: number;

addReplaceHighlights()

addReplaceHighlights(
   pageIndex, 
   highlights, 
   args?): object;

Adds multiple replace text highlights to the specified page's replaced highlights map.

Note for Users

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.

Parameters

pageIndex

number

The index of the page where the highlights should be added.

highlights

ICustomHighlight[]

An array of highlight objects to add.

args?

HighlightBehaviorArgs

Optional behavior arguments, such as whether to skip repainting the text layer after adding the highlights.

Returns

object

The start and end indices range of the added replace highlights.

end
end: number;
start
start: number;

cleanupDocument()

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.

Returns

void


clearAllHighlights()

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.

Parameters

args?

HighlightBehaviorArgs

Optional behavior arguments. If skipPaint is true, the text layer will not be repainted immediately after clearing the highlights.

Returns

void

Examples

// 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()

clearAllReplaceHighlights(args?): void;

Clears all replaced highlights for a specified page.

Note for Users

Replace highlights are used internally by the viewer to display replaced text segments. For clearing regular highlights, use clearHighlightedSegments or clearAllHighlights instead.

Parameters

args?

HighlightBehaviorArgs

Returns

void


clearHighlightedSegments()

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.

Parameters

pageIndex

The index of the page or an array of page indices to clear highlights from.

number | number[]

args?

HighlightBehaviorArgs

Returns

void

Examples

// Clear highlights from page 3:
highlightManager.clearHighlightedSegments(3);
// Clear highlights from pages 1, 4, and 5:
highlightManager.clearHighlightedSegments([1, 4, 5]);

getHighlightsForPage()

getHighlightsForPage(pageIndex): ICustomHighlight[];

Retrieves all highlights for a specified page.

Returns an array of highlight objects present on the given page.

Parameters

pageIndex

number

The index of the page to retrieve highlights from (0-based).

Returns

ICustomHighlight[]

An array of highlights on the specified page.

Example

// Get all highlights from page 2:
const highlights = viewer.getHighlights(2);

getReplaceTextData()

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.

Returns

ReplaceTextModel[]

An array of ReplaceTextModel objects, or undefined if no replace highlights are found.


hasReplaceHighlight()

hasReplaceHighlight(pageIndex, hashId): boolean;

Checks if a replace highlight exists for the given page and hash ID.

Note for Users

Replace highlights are used internally by the viewer to display replaced text segments. For checking regular highlights, use getHighlightsForPage instead.

Parameters

pageIndex

number

The index of the page to check.

hashId

string

The unique hash ID of the replace highlight to check.

Returns

boolean

true if the replace highlight exists, otherwise false.


highlightTextSegment()

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.

Parameters

pageIndex

number

The index of the page where the text segment is located (0-based).

startCharIndex

number

The starting character index (0-based) of the text segment to highlight.

endCharIndex

number

The ending character index (0-based) of the text segment to highlight.

args?

Optional parameters to customize the appearance and behavior of the highlight.

borderColor?

string

The border color for the highlight in rgba, hex, or named color format.

borderWidth?

number

The width of the highlight border in pixels.

clearPrevious?

boolean

If true, clears existing highlights before adding the new one.

color?

string

The fill color for the highlight in rgba, hex, or named color format.

skipPaint?

boolean

If true, skips the immediate repaint of the text layer after adding the highlight.

Returns

Promise<boolean>

A promise that resolves once the highlight has been added.

Example

// 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()

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.

Parameters

pageIndex

number

The index of the page from which to remove the highlight (0-based).

index

number

The index of the highlight to remove within the specified page.

args?

HighlightBehaviorArgs

Optional behavior arguments, such as whether to skip repainting the text layer after removing the highlight.

Returns

void

Examples

// 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()

removeReplaceHighlight(
   pageIndex, 
   index, 
   args?): void;

Removes a replace highlight from the specified page's replaced highlights map by its index.

Note for Users

Replace highlights are used internally by the viewer to display replaced text segments. For regular highlight management, use removeHighlight instead.

Parameters

pageIndex

number

The index of the page where the highlight should be removed.

index

number

The index of the highlight in the replaceHighlights array to remove.

args?

HighlightBehaviorArgs

Optional behavior arguments, such as whether to skip repainting the text layer.

Returns

void


removeReplaceHighlights()

removeReplaceHighlights(
   pageIndex, 
   indices, 
   args?): void;

Removes replace highlights from the specified page's replaced highlights map by their index range.

Note for Users

Replace highlights are used internally by the viewer to display replaced text segments. For regular highlight management, use removeHighlight instead.

Parameters

pageIndex

number

The index of the page where the highlights should be removed.

indices

The range of indices specifying which highlights to remove.

end

number

start

number

args?

HighlightBehaviorArgs

Optional behavior arguments, such as whether to skip repainting the text layer.

Returns

void


repaintTextLayer()

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.

Parameters

pageIndices

The index or indices of the pages to repaint.

number | number[]

Returns

void

Examples

// Repaint the text layer for page 1:
highlightManager.repaintTextLayer(1);
// Repaint the text layer for pages 2 and 3:
highlightManager.repaintTextLayer([2, 3]);