Show / Hide Table of Contents

# Class Highlights

Highlights is used to store the necessary information and perform certain tasks in accordance with Adobe's Highlight standard, whose details can be found at:

http://partners.adobe.com/public/developer/en/pdf/HighlightFileFormat.pdf

In a nutshell, the Highlights class maintains a set of highlights. Each highlight contains three pieces of information:

page: the number of the page this Highlight is on; position: the start position (text offset) of this Highlight; length: the length of this Highlight.

Possible use case scenarios for Highlights include:

- Load a Highlight file (in XML format) and highlight the corresponding texts in the viewer (e.g., if the viewer is implemented using PDFViewCtrl, it can be achieved simply by calling PDFViewCtrl::SelectByHighlights() method);
- Save the Highlight information (e.g., constructed by the TextSearch class) to an XML file for external uses.

Note:

- The Highlights class does not maintain the corresponding PDF document for its highlights. It is the user's responsibility to match them up.
- The Highlights class ensures that each highlight it maintains is unique (no two highlights have the same page, position and length values).
- The current implementation of Highlights only supports the 'characters' encoding for 'units' as described in the format; the 'words' encoding is not supported at this point.

##### Inheritance

object
Highlights

##### Implements

IDisposable

##### Inherited Members

object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()

###### Namespace: pdftron.PDF

###### Assembly: PDFTronDotNet.dll

##### Syntax

    public class Highlights : IDisposable

##### Remarks

For a sample code, please take a look at the TextSearchTest sample project.

### Constructors

#### Highlights()

Creates a default `Highlights` object

##### Declaration

    public Highlights()

#### Highlights(Highlights)

Creates a Highlights from a given object

##### Declaration

    public Highlights(Highlights hlts)

##### Parameters

Type | Name | Description
--- | --- | ---
Highlights | hlts | a given `Highlights` object

### Methods

#### Add(Highlights)

Add extra Highlight information into the class.

##### Declaration

    public void Add(Highlights hlts)

##### Parameters

Type | Name | Description
--- | --- | ---
Highlights | hlts | the Highlights of which the Highlight information is to be added.

#### Begin(PDFDoc)

Rewind the internal pointer to the first highlight.

##### Declaration

    public void Begin(PDFDoc doc)

##### Parameters

Type | Name | Description
--- | --- | ---
PDFDoc | doc | the PDF document to which the highlights correspond.

##### Remarks

the PDF document can be a dummy document unless getCurrentQuads() is to be called.

#### Clear()

Clear the current Highlight information in the class.

##### Declaration

    public void Clear()

#### Destroy()

##### Declaration

    public void Destroy()

#### Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

##### Declaration

    public void Dispose()

#### Dispose(bool)

##### Declaration

    protected virtual void Dispose(bool disposing)

##### Parameters

Type | Name | Description
--- | --- | ---
bool | disposing |

#### ~Highlights()

Releases all resources used by the Highlights

##### Declaration

    protected ~Highlights()

#### GetCurrentPageNumber()

Get the page number of the current highlight.

##### Declaration

    public int GetCurrentPageNumber()

##### Returns

Type | Description
--- | ---
int | the current page number

#### GetCurrentQuads()

Get the corresponding quadrangles of the current highlight.

##### Declaration

    public double[] GetCurrentQuads()

##### Returns

Type | Description
--- | ---
double[] | the output quadrangles. Each quadrangle has eight doubles (x1, y1), (x2, y2), (x3, y3), (x4, y4) denoting the four vertices in counter-clockwise order.

##### Remarks

since a highlight may correspond to multiple quadrangles, e.g., when it crosses a line, the number of resulting quadrangles may be larger than 1.

#### GetCurrentTextRange()

Get a `TextRange` object that represents the current highlight.

##### Declaration

    public TextRange GetCurrentTextRange()

##### Returns

Type | Description
--- | ---
TextRange | the current text range

#### HasNext()

Query if there is any subsequent highlight after the current highlight.

##### Declaration

    public bool HasNext()

##### Returns

Type | Description
--- | ---
bool | true, if successful

#### Load(string)

Load the Highlight information from a file. Note that the pre-existing Highlight information is discarded.

##### Declaration

    public void Load(string file_name)

##### Parameters

Type | Name | Description
--- | --- | ---
string | file_name | the name of the file to load from.

#### Next()

Move the current highlight to the next highlight.

##### Declaration

    public void Next()

#### Save(string)

Save the current Highlight information in the class to a file.

##### Declaration

    public void Save(string file_name)

##### Parameters

Type | Name | Description
--- | --- | ---
string | file_name | the name of the file to save to.

#### SaveToString()

Save the current Highlight information in the class to an XML string.

##### Declaration

    public string SaveToString()

##### Returns

Type | Description
--- | ---
string | the highlight XML file contents as a string

### Implements

IDisposable