PdfAnnotationCollection
Represents a collection of annotations on a PDF page. Provides methods to access, add, and remove annotations.
using Nutrient;The SDK creates this class through factory methods or other SDK objects.
Collection access
PdfAnnotationCollection implements IReadOnlyList<PdfAnnotation>, so you can index it, read its Count, and iterate it with foreach.
public PdfAnnotation this[int index] { get; }Gets the element at the specified 0-based index. Type: PdfAnnotation
Properties
Count
public int Count { get; }The number of annotations in the collection.
Type: int
Methods
AddCircle
public PdfCircleAnnotation AddCircle(float x, float y, float width, float height, string author, string contents)Adds a circle (ellipse) annotation to this page.
Parameters
| Name | Type | Description |
|---|---|---|
x | float | The x coordinate of the bounding rectangle in points. |
y | float | The y coordinate of the bounding rectangle in points. |
width | float | The width of the bounding rectangle in points. |
height | float | The height of the bounding rectangle in points. |
author | string | The author of the annotation. |
contents | string | The text contents/comment for the annotation. |
Returns: PdfCircleAnnotation - The newly created PdfCircleAnnotation. Throws: NutrientException - Thrown when no page is loaded.
Throws: NutrientException - Thrown when the operation fails.
AddFreeText
public PdfFreeTextAnnotation AddFreeText(float x, float y, float width, float height, string author, string contents, string fontName, float fontSize, Color fontColor)Adds a free text annotation (text box) to this page.
Parameters
| Name | Type | Description |
|---|---|---|
x | float | The x coordinate of the text box in points. |
y | float | The y coordinate of the text box in points. |
width | float | The width of the text box in points. |
height | float | The height of the text box in points. |
author | string | The author of the annotation. |
contents | string | The text contents to display. |
fontName | string | The name of the font to use. |
fontSize | float | The size of the font in points. |
fontColor | Color | The color of the text. |
Returns: PdfFreeTextAnnotation - The newly created PdfFreeTextAnnotation. Throws: NutrientException - Thrown when no page is loaded.
Throws: NutrientException - Thrown when the operation fails.
AddHighlight
public PdfHighlightAnnotation AddHighlight(float x, float y, float width, float height, string author, string contents)Adds a highlight annotation to this page.
Parameters
| Name | Type | Description |
|---|---|---|
x | float | The x coordinate of the highlight area in points. |
y | float | The y coordinate of the highlight area in points. |
width | float | The width of the highlight area in points. |
height | float | The height of the highlight area in points. |
author | string | The author of the annotation. |
contents | string | The text contents/comment for the annotation. |
Returns: PdfHighlightAnnotation - The newly created PdfHighlightAnnotation. Throws: NutrientException - Thrown when no page is loaded.
Throws: NutrientException - Thrown when the operation fails.
AddLine
public PdfLineAnnotation AddLine(float startX, float startY, float endX, float endY, string author, string contents)Adds a line annotation to this page.
Parameters
| Name | Type | Description |
|---|---|---|
startX | float | X coordinate of the line start point in points. |
startY | float | Y coordinate of the line start point in points. |
endX | float | X coordinate of the line end point in points. |
endY | float | Y coordinate of the line end point in points. |
author | string | The author of the annotation. |
contents | string | The text contents/comment for the annotation. |
Returns: PdfLineAnnotation - The newly created PdfLineAnnotation. Throws: NutrientException - Thrown when no page is loaded.
Throws: NutrientException - Thrown when the operation fails.
AddLink
public PdfLinkAnnotation AddLink(float x, float y, float width, float height)Adds an empty link annotation to this page. Use the returned annotation’s URI property or SetDestination method to configure the link target.
Parameters
| Name | Type | Description |
|---|---|---|
x | float | The x coordinate of the link area in points. |
y | float | The y coordinate of the link area in points. |
width | float | The width of the link area in points. |
height | float | The height of the link area in points. |
Returns: PdfLinkAnnotation - The newly created PdfLinkAnnotation. Throws: NutrientException - Thrown when no page is loaded.
Throws: NutrientException - Thrown when the operation fails.
AddRedact
public PdfRedactAnnotation AddRedact(float x, float y, float width, float height)Adds a redaction annotation to this page. The annotation marks content for redaction but does not apply the redaction until ApplyRedactions is called.
Parameters
| Name | Type | Description |
|---|---|---|
x | float | The x coordinate of the redaction area in points. |
y | float | The y coordinate of the redaction area in points. |
width | float | The width of the redaction area in points. |
height | float | The height of the redaction area in points. |
Returns: PdfRedactAnnotation - The newly created PdfRedactAnnotation. Throws: NutrientException - Thrown when no page is loaded.
Throws: NutrientException - Thrown when the operation fails.
AddSquare
public PdfSquareAnnotation AddSquare(float x, float y, float width, float height, string author, string contents)Adds a square (rectangle) annotation to this page.
Parameters
| Name | Type | Description |
|---|---|---|
x | float | The x coordinate of the rectangle in points. |
y | float | The y coordinate of the rectangle in points. |
width | float | The width of the rectangle in points. |
height | float | The height of the rectangle in points. |
author | string | The author of the annotation. |
contents | string | The text contents/comment for the annotation. |
Returns: PdfSquareAnnotation - The newly created PdfSquareAnnotation. Throws: NutrientException - Thrown when no page is loaded.
Throws: NutrientException - Thrown when the operation fails.
AddSquiggly
public PdfSquigglyAnnotation AddSquiggly(float x, float y, float width, float height, string author, string contents)Adds a squiggly underline annotation to this page.
Parameters
| Name | Type | Description |
|---|---|---|
x | float | The x coordinate of the squiggly area in points. |
y | float | The y coordinate of the squiggly area in points. |
width | float | The width of the squiggly area in points. |
height | float | The height of the squiggly area in points. |
author | string | The author of the annotation. |
contents | string | The text contents/comment for the annotation. |
Returns: PdfSquigglyAnnotation - The newly created PdfSquigglyAnnotation. Throws: NutrientException - Thrown when no page is loaded.
Throws: NutrientException - Thrown when the operation fails.
AddStamp
public PdfStampAnnotation AddStamp(float x, float y, float width, float height, string title, string contents)Adds a rubber stamp annotation to this page.
Parameters
| Name | Type | Description |
|---|---|---|
x | float | The x coordinate of the stamp in points. |
y | float | The y coordinate of the stamp in points. |
width | float | The width of the stamp in points. |
height | float | The height of the stamp in points. |
title | string | The title of the annotation. |
contents | string | The text contents of the annotation. |
Returns: PdfStampAnnotation - The newly created PdfStampAnnotation. Throws: NutrientException - Thrown when no page is loaded.
Throws: NutrientException - Thrown when the operation fails.
AddStickyNote
public PdfTextAnnotation AddStickyNote(float x, float y, string author, string subject, string contents)Adds a sticky note (text) annotation to this page.
Parameters
| Name | Type | Description |
|---|---|---|
x | float | The x coordinate of the annotation in points. |
y | float | The y coordinate of the annotation in points. |
author | string | The author of the annotation. |
subject | string | The subject of the annotation. |
contents | string | The text contents of the annotation. |
Returns: PdfTextAnnotation - The newly created PdfTextAnnotation. Throws: NutrientException - Thrown when no page is loaded.
Throws: NutrientException - Thrown when the operation fails.
AddStrikeOut
public PdfStrikeOutAnnotation AddStrikeOut(float x, float y, float width, float height, string author, string contents)Adds a strikeout annotation to this page.
Parameters
| Name | Type | Description |
|---|---|---|
x | float | The x coordinate of the strikeout area in points. |
y | float | The y coordinate of the strikeout area in points. |
width | float | The width of the strikeout area in points. |
height | float | The height of the strikeout area in points. |
author | string | The author of the annotation. |
contents | string | The text contents/comment for the annotation. |
Returns: PdfStrikeOutAnnotation - The newly created PdfStrikeOutAnnotation. Throws: NutrientException - Thrown when no page is loaded.
Throws: NutrientException - Thrown when the operation fails.
AddUnderline
public PdfUnderlineAnnotation AddUnderline(float x, float y, float width, float height, string author, string contents)Adds an underline annotation to this page.
Parameters
| Name | Type | Description |
|---|---|---|
x | float | The x coordinate of the underline area in points. |
y | float | The y coordinate of the underline area in points. |
width | float | The width of the underline area in points. |
height | float | The height of the underline area in points. |
author | string | The author of the annotation. |
contents | string | The text contents/comment for the annotation. |
Returns: PdfUnderlineAnnotation - The newly created PdfUnderlineAnnotation. Throws: NutrientException - Thrown when no page is loaded.
Throws: NutrientException - Thrown when the operation fails.
RemoveAt
public void RemoveAt(int index)Removes the annotation at the specified index.
Parameters
| Name | Type | Description |
|---|---|---|
index | int | The 0-based index of the annotation to remove. |
Throws: NutrientException - Thrown when no page is loaded.
Throws: NutrientException - Thrown when the index is out of range.
Throws: NutrientException - Thrown when the operation fails.
Resource management
public void Dispose()PdfAnnotationCollection implements IDisposable. Call Dispose() or use a C# using declaration to release its native handle right away. If you don’t, the handle is released when the object is garbage collected.