# Interface IHighlightManager

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

#### Hierarchy

- IHighlightManager

#####
Index

### Methods

addHighlight
addReplaceHighlight
addReplaceHighlights
cleanupDocument
clearAllHighlights
clearAllReplaceHighlights
clearHighlightedSegments
getHighlightsForPage
getReplaceTextData
hasReplaceHighlight
highlightTextSegment
removeHighlight
removeReplaceHighlight
removeReplaceHighlights
repaintTextLayer

## Methods

### addHighlight

- addHighlight(pageIndex: number, highlight: ICustomHighlight, args?: HighlightBehaviorArgs): number

- Adds a custom highlight directly to a specified page.

  This method allows you to add a predefined highlight object to a specific page.

  ### 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);

  #### Parameters

  - ##### pageIndex: number

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

  - ##### highlight: ICustomHighlight

    The highlight object to add.

  - ##### `Optional` args: HighlightBehaviorArgs

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

  #### Returns number

### addReplaceHighlight

- addReplaceHighlight(pageIndex: number, highlight: ICustomHighlight, args?: HighlightBehaviorArgs): { end: number; start: number }

- 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.

  ### Returns

  The start and end indices of the added replace highlight.

  #### Parameters

  - ##### pageIndex: number

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

  - ##### highlight: ICustomHighlight

    The highlight object to add.

  - ##### `Optional` args: HighlightBehaviorArgs

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

  #### Returns { end: number; start: number }

  - ##### end: number

  - ##### start: number

### addReplaceHighlights

- addReplaceHighlights(pageIndex: number, highlights: ICustomHighlight[], args?: HighlightBehaviorArgs): { end: number; start: number }

- 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.

  ### Returns

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

  #### Parameters

  - ##### pageIndex: number

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

  - ##### highlights: ICustomHighlight[]

    An array of highlight objects to add.

  - ##### `Optional` args: HighlightBehaviorArgs

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

  #### Returns { end: number; start: number }

  - ##### end: number

  - ##### 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?: HighlightBehaviorArgs): 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.

  ### Example

      // Clear all highlights from the entire document and repaint the text layer:
      highlightManager.clearAllHighlights();

  ### Example

      // Clear all highlights from the entire document and skip repainting:
      highlightManager.clearAllHighlights({ skipPaint: true });

  #### Parameters

  - ##### `Optional` args: HighlightBehaviorArgs

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

  #### Returns void

### clearAllReplaceHighlights

- clearAllReplaceHighlights(args?: HighlightBehaviorArgs): 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

  - ##### `Optional` args: HighlightBehaviorArgs

  #### Returns void

### clearHighlightedSegments

- clearHighlightedSegments(pageIndex: number | number[], args?: HighlightBehaviorArgs): 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.

  ### Example

      // Clear highlights from page 3:
      highlightManager.clearHighlightedSegments(3);

  ### Example

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

  #### Parameters

  - ##### pageIndex: number | number[]

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

  - ##### `Optional` args: HighlightBehaviorArgs

  #### Returns void

### getHighlightsForPage

- getHighlightsForPage(pageIndex: number): ICustomHighlight[]

- Retrieves all highlights for a specified page.

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

  ### Returns

  An array of highlights on the specified page.

  ### Example

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

  #### Parameters

  - ##### pageIndex: number

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

  #### Returns ICustomHighlight[]

### getReplaceTextData

- getReplaceTextData(): undefined | 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

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

  #### Returns undefined | ReplaceTextModel[]

### hasReplaceHighlight

- hasReplaceHighlight(pageIndex: number, hashId: string): 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.

  ### Returns

  `true` if the replace highlight exists, otherwise `false`.

  #### Parameters

  - ##### pageIndex: number

    The index of the page to check.

  - ##### hashId: string

    The unique hash ID of the replace highlight to check.

  #### Returns boolean

### highlightTextSegment

- highlightTextSegment(pageIndex: number, startCharIndex: number, endCharIndex: number, args?: { borderColor?: string; borderWidth?: number; clearPrevious?: boolean; color?: string; skipPaint?: boolean }): 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.

  ### Returns

  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)' });

  #### 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.

  - ##### `Optional` args: { borderColor?: string; borderWidth?: number; clearPrevious?: boolean; color?: string; skipPaint?: boolean }

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

    - ##### `Optional` borderColor?: string

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

    - ##### `Optional` borderWidth?: number

      The width of the highlight border in pixels.

    - ##### `Optional` clearPrevious?: boolean

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

    - ##### `Optional` color?: string

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

    - ##### `Optional` skipPaint?: boolean

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

  #### Returns Promise<boolean>

### removeHighlight

- removeHighlight(pageIndex: number, index: number, args?: HighlightBehaviorArgs): void

- Removes a specific highlight from a page.

  This method removes a highlight at a specified index from the highlights on a given page.

  ### Example

      // Remove the first highlight from page 2:
      viewer.removeHighlight(2, 0);

  ### Example

      // Remove the second highlight from page 1 and skip repainting:
      viewer.removeHighlight(1, 1, { skipPaint: true });

  #### 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.

  - ##### `Optional` args: HighlightBehaviorArgs

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

  #### Returns void

### removeReplaceHighlight

- removeReplaceHighlight(pageIndex: number, index: number, args?: HighlightBehaviorArgs): 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.

  - ##### `Optional` args: HighlightBehaviorArgs

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

  #### Returns void

### removeReplaceHighlights

- removeReplaceHighlights(pageIndex: number, indices: { end: number; start: number }, args?: HighlightBehaviorArgs): 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: { end: number; start: number }

    The range of indices specifying which highlights to remove.

    - ##### end: number

    - ##### start: number

  - ##### `Optional` args: HighlightBehaviorArgs

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

  #### Returns void

### repaintTextLayer

- repaintTextLayer(pageIndices: number | number[]): 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.

  ### Example

      // Repaint the text layer for page 1:
      highlightManager.repaintTextLayer(1);

  ### Example

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

  #### Parameters

  - ##### pageIndices: number | number[]

    The index or indices of the pages to repaint.

  #### Returns void