PdfAnnotationCollection Class

The annotations of a page: the /Annots array (ISO 32000-2, 12.5).

Remarks

The annotations are read once and kept until the /Annots array changes, through the collection or the object model: PdfAnnotationCollection.Count and the indexer do not read the array again, and an annotation is the same instance until then.

Implements

Properties

NameDescription
CountGets the number of annotations.

Gets the number of annotations.

public int Count { get; }

Property value

int

Indexers

NameDescription
this[int]Gets an annotation.

Gets an annotation.

public PdfAnnotation this[int index] { get; }

Parameters

index int
The index.

Property value

PdfAnnotation

Methods

NameDescription
AddCaret(PdfRectangle, string?, PdfColor?)Adds a caret annotation (12.5.6.11): a symbol that marks where text is to be inserted.
AddCircle(PdfRectangle, PdfColor?, PdfColor?, double)Adds a circle annotation (12.5.6.8): an ellipse inscribed in a rectangle.
AddFileAttachment(PdfRectangle, PdfEmbeddedFile, PdfFileAttachmentIcon)Adds a file attachment annotation (12.5.6.15) that holds a file of the document, such as a file of PdfDocument.EmbeddedFiles.
AddFileAttachment(PdfRectangle, string, ReadOnlySpan<byte>, PdfEmbeddedFileOptions?, PdfFileAttachmentIcon)Adds a file attachment annotation (12.5.6.15) that embeds a new file.
AddFreeText(PdfRectangle, string, PdfStandardFont, double, PdfColor?)Adds a free text annotation (12.5.6.6): a text drawn on the page, in a box with a border.
AddInk(IEnumerable<IEnumerable<PdfPoint>>, PdfColor?, double)Adds an ink annotation (12.5.6.13): freehand strokes, as drawn with a pen, with round caps and joins.
AddLine(PdfPoint, PdfPoint, PdfColor?, double, PdfLineEnding, PdfLineEnding)Adds a line annotation (12.5.6.7): a straight line, with endings such as arrows.
AddLink(PdfRectangle, PdfDestination)Adds a link that goes to a destination of the document.
AddLink(PdfRectangle, Uri)Adds a link that opens a URI.
AddNote(PdfPoint, string, PdfColor?)Adds a note (a text annotation, 12.5.6.4): an icon that opens a text, drawn with the color.
AddPolyLine(IEnumerable<PdfPoint>, PdfColor?, double, PdfLineEnding, PdfLineEnding)Adds a polyline annotation (12.5.6.9): connected straight lines, with endings such as arrows at the first and last vertices.
AddPolygon(IEnumerable<PdfPoint>, PdfColor?, PdfColor?, double)Adds a polygon annotation (12.5.6.9): a closed shape of vertices.
AddPopup(PdfMarkupAnnotation, PdfRectangle, bool)Adds the pop-up annotation of a markup annotation (12.5.6.14): the window that shows its text, and sets its PdfMarkupAnnotation.Popup.
AddRedaction(IEnumerable<PdfRectangle>, string?, PdfColor?)Adds a redaction annotation (12.5.6.23): marks regions whose content is to be removed. The content stays until the redaction is applied, by PdfDocument.ApplyRedactions or by a viewer; until then, the regions are outlined in red.
AddReply(PdfMarkupAnnotation, string, string?)Adds a reply to a markup annotation (12.5.6.2): a text annotation in reply to it (/IRT), at the same place. Viewers list the replies in the thread of the annotation; the reply has an empty appearance, so that it does not draw a second icon.
AddSquare(PdfRectangle, PdfColor?, PdfColor?, double)Adds a square annotation (12.5.6.8): a rectangle.
AddStamp(PdfRectangle, string, PdfColor?)Adds a rubber stamp annotation (12.5.6.12): a word, such as APPROVED or DRAFT, in a frame with rounded corners.
AddTextMarkup(PdfTextMarkupKind, IEnumerable<PdfRectangle>, PdfColor?, string?)Adds a text markup annotation (12.5.6.10): a highlight, an underline, a squiggly underline or a strikeout of regions of the page, such as the lines of a text.
GetEnumerator()Returns an enumerator over the annotations.
Remove(PdfAnnotation)Removes an annotation from the page, with the references that would keep it in a saved file: its pop-up annotation, the /IRT and /Popup entries of the other annotations of the page that point to it, the object references of the structure tree, and, for a widget, its entry in its form field.
System.Collections.IEnumerable.GetEnumerator()

AddCaret(PdfRectangle, string?, PdfColor?)

PdfAnnotationCollection.cs

Adds a caret annotation (12.5.6.11): a symbol that marks where text is to be inserted.

public PdfCaretAnnotation AddCaret(PdfRectangle rectangle, string? text = null, PdfColor? color = null)

Parameters

rectangle PdfRectangle
The rectangle of the caret, in default user space.
text string?
The text to insert, or a comment, or null.
color PdfColor?
The color of the caret, or null for blue.

Returns

PdfCaretAnnotation The annotation.

AddCircle(PdfRectangle, PdfColor?, PdfColor?, double)

PdfAnnotationCollection.cs

Adds a circle annotation (12.5.6.8): an ellipse inscribed in a rectangle.

public PdfCircleAnnotation AddCircle(PdfRectangle rectangle, PdfColor? color = null, PdfColor? interiorColor = null, double width = 1d)

Parameters

rectangle PdfRectangle
The rectangle, in default user space: the border is drawn inside it.
color PdfColor?
The color of the border, or null for red.
interiorColor PdfColor?
The color that fills the ellipse, or null for none.
width double
The width of the border, in points; 0 for none.

Returns

PdfCircleAnnotation The annotation.

Exceptions

ArgumentOutOfRangeException
width is negative or not finite.

AddFileAttachment overloads

AddFileAttachment(PdfRectangle, PdfEmbeddedFile, PdfFileAttachmentIcon)

PdfAnnotationCollection.cs

Adds a file attachment annotation (12.5.6.15) that holds a file of the document, such as a file of PdfDocument.EmbeddedFiles.

Parameters
rectangle PdfRectangle
The region of the icon, in default user space.
file PdfEmbeddedFile
The file.
icon PdfFileAttachmentIcon
The icon of the annotation.
Returns

PdfFileAttachmentAnnotation The annotation. Its PdfAnnotation.Contents, the text that describes it, is the description of the file or its name.

Exceptions
ArgumentException
The file is not an indirect object of the document.

AddFileAttachment(PdfRectangle, string, ReadOnlySpan<byte>, PdfEmbeddedFileOptions?, PdfFileAttachmentIcon)

PdfAnnotationCollection.cs

Adds a file attachment annotation (12.5.6.15) that embeds a new file.

public PdfFileAttachmentAnnotation AddFileAttachment(PdfRectangle rectangle, string fileName, ReadOnlySpan<byte> data, PdfEmbeddedFileOptions? options = null, PdfFileAttachmentIcon icon = PdfFileAttachmentIcon.PushPin)
Parameters
rectangle PdfRectangle
The region of the icon, in default user space.
fileName string
The name of the file.
data ReadOnlySpan<byte>
The content of the file.
options PdfEmbeddedFileOptions?
The attributes of the file, or null for the defaults.
icon PdfFileAttachmentIcon
The icon of the annotation.
Returns

PdfFileAttachmentAnnotation The annotation. Its PdfAnnotation.Contents, the text that describes it, is the description of the file or its name.

Exceptions
ArgumentException
fileName is empty, or the MIME type is not valid.

AddFreeText(PdfRectangle, string, PdfStandardFont, double, PdfColor?)

PdfAnnotationCollection.cs

Adds a free text annotation (12.5.6.6): a text drawn on the page, in a box with a border.

public PdfMarkupAnnotation AddFreeText(PdfRectangle rectangle, string text, PdfStandardFont font = PdfStandardFont.Helvetica, double fontSize = 12d, PdfColor? color = null)

Parameters

rectangle PdfRectangle
The box, in default user space.
text string
The text: it is broken into lines that fit the box.
font PdfStandardFont
The font, a standard font: the default appearance string of the annotation (/DA) names it.
fontSize double
The font size.
color PdfColor?
The color of the text and of the border, or null for black.

Returns

PdfMarkupAnnotation The annotation.

Exceptions

ArgumentException
A character of the text has no glyph in the font.

AddInk(IEnumerable<IEnumerable<PdfPoint>>, PdfColor?, double)

PdfAnnotationCollection.cs

Adds an ink annotation (12.5.6.13): freehand strokes, as drawn with a pen, with round caps and joins.

public PdfInkAnnotation AddInk(IEnumerable<IEnumerable<PdfPoint>> strokes, PdfColor? color = null, double width = 1d)

Parameters

strokes IEnumerable<IEnumerable<PdfPoint>>
The strokes: each one a list of points, in default user space.
color PdfColor?
The color of the strokes, or null for red.
width double
The width of the strokes, in points.

Returns

PdfInkAnnotation The annotation.

Exceptions

ArgumentException
There is no stroke, a stroke is empty, or a coordinate is not a finite number.
ArgumentOutOfRangeException
width is negative or not finite.

AddLine(PdfPoint, PdfPoint, PdfColor?, double, PdfLineEnding, PdfLineEnding)

PdfAnnotationCollection.cs

Adds a line annotation (12.5.6.7): a straight line, with endings such as arrows.

public PdfLineAnnotation AddLine(PdfPoint start, PdfPoint end, PdfColor? color = null, double width = 1d, PdfLineEnding startEnding = PdfLineEnding.None, PdfLineEnding endEnding = PdfLineEnding.None)

Parameters

start PdfPoint
The start of the line, in default user space.
end PdfPoint
The end of the line, in default user space.
color PdfColor?
The color of the line, or null for red.
width double
The width of the line, in points.
startEnding PdfLineEnding
The ending at start.
endEnding PdfLineEnding
The ending at end.

Returns

PdfLineAnnotation The annotation. Its closed endings are filled with the color of the line (PdfLineAnnotation.InteriorColor).

Exceptions

ArgumentException
A coordinate is not a finite number.
ArgumentOutOfRangeException
width is negative or not finite.

AddNote(PdfPoint, string, PdfColor?)

PdfAnnotationCollection.cs

Adds a note (a text annotation, 12.5.6.4): an icon that opens a text, drawn with the color.

public PdfMarkupAnnotation AddNote(PdfPoint position, string text, PdfColor? color = null)

Parameters

position PdfPoint
The lower-left corner of the icon, in default user space; the icon is 20 x 20.
text string
The text of the note.
color PdfColor?
The color of the icon, or null for yellow.

Returns

PdfMarkupAnnotation The note.

AddPolyLine(IEnumerable<PdfPoint>, PdfColor?, double, PdfLineEnding, PdfLineEnding)

PdfAnnotationCollection.cs

Adds a polyline annotation (12.5.6.9): connected straight lines, with endings such as arrows at the first and last vertices.

public PdfPolyLineAnnotation AddPolyLine(IEnumerable<PdfPoint> vertices, PdfColor? color = null, double width = 1d, PdfLineEnding startEnding = PdfLineEnding.None, PdfLineEnding endEnding = PdfLineEnding.None)

Parameters

vertices IEnumerable<PdfPoint>
The vertices, in default user space: at least 2.
color PdfColor?
The color of the lines, or null for red.
width double
The width of the lines, in points.
startEnding PdfLineEnding
The ending at the first vertex.
endEnding PdfLineEnding
The ending at the last vertex.

Returns

PdfPolyLineAnnotation The annotation. Its closed endings are filled with the color of the lines.

Exceptions

ArgumentException
There are fewer than 2 vertices, or a coordinate is not a finite number.
ArgumentOutOfRangeException
width is negative or not finite.

AddPolygon(IEnumerable<PdfPoint>, PdfColor?, PdfColor?, double)

PdfAnnotationCollection.cs

Adds a polygon annotation (12.5.6.9): a closed shape of vertices.

public PdfPolygonAnnotation AddPolygon(IEnumerable<PdfPoint> vertices, PdfColor? color = null, PdfColor? interiorColor = null, double width = 1d)

Parameters

vertices IEnumerable<PdfPoint>
The vertices, in default user space: at least 2.
color PdfColor?
The color of the border, or null for red.
interiorColor PdfColor?
The color that fills the polygon, or null for none.
width double
The width of the border, in points; 0 for none.

Returns

PdfPolygonAnnotation The annotation.

Exceptions

ArgumentException
There are fewer than 2 vertices, or a coordinate is not a finite number.
ArgumentOutOfRangeException
width is negative or not finite.

AddPopup(PdfMarkupAnnotation, PdfRectangle, bool)

PdfAnnotationCollection.cs

Adds the pop-up annotation of a markup annotation (12.5.6.14): the window that shows its text, and sets its PdfMarkupAnnotation.Popup.

public PdfPopupAnnotation AddPopup(PdfMarkupAnnotation parent, PdfRectangle rectangle, bool isOpen = false)

Parameters

parent PdfMarkupAnnotation
The markup annotation, on this page.
rectangle PdfRectangle
The rectangle of the window, in default user space.
isOpen bool
Whether the window is initially open.

Returns

PdfPopupAnnotation The pop-up annotation.

Exceptions

ArgumentException
The annotation is not on this page.

AddRedaction(IEnumerable<PdfRectangle>, string?, PdfColor?)

PdfAnnotationCollection.cs

Adds a redaction annotation (12.5.6.23): marks regions whose content is to be removed. The content stays until the redaction is applied, by PdfDocument.ApplyRedactions or by a viewer; until then, the regions are outlined in red.

public PdfRedactAnnotation AddRedaction(IEnumerable<PdfRectangle> regions, string? overlayText = null, PdfColor? interiorColor = null)

Parameters

regions IEnumerable<PdfRectangle>
The regions, in default user space.
overlayText string?
The text drawn in the regions once they are redacted, or null.
interiorColor PdfColor?
The color that fills the regions once they are redacted, or null for black.

Returns

PdfRedactAnnotation The annotation.

Exceptions

ArgumentException
There is no region.

AddReply(PdfMarkupAnnotation, string, string?)

PdfAnnotationCollection.cs

Adds a reply to a markup annotation (12.5.6.2): a text annotation in reply to it (/IRT), at the same place. Viewers list the replies in the thread of the annotation; the reply has an empty appearance, so that it does not draw a second icon.

public PdfTextAnnotation AddReply(PdfMarkupAnnotation parent, string text, string? author = null)

Parameters

parent PdfMarkupAnnotation
The annotation, on this page.
text string
The text of the reply.
author string?
The author of the reply, or null.

Returns

PdfTextAnnotation The reply.

Exceptions

ArgumentException
The annotation is not on this page.

AddSquare(PdfRectangle, PdfColor?, PdfColor?, double)

PdfAnnotationCollection.cs

Adds a square annotation (12.5.6.8): a rectangle.

public PdfSquareAnnotation AddSquare(PdfRectangle rectangle, PdfColor? color = null, PdfColor? interiorColor = null, double width = 1d)

Parameters

rectangle PdfRectangle
The rectangle, in default user space: the border is drawn inside it.
color PdfColor?
The color of the border, or null for red.
interiorColor PdfColor?
The color that fills the rectangle, or null for none.
width double
The width of the border, in points; 0 for none.

Returns

PdfSquareAnnotation The annotation.

Exceptions

ArgumentOutOfRangeException
width is negative or not finite.

AddStamp(PdfRectangle, string, PdfColor?)

PdfAnnotationCollection.cs

Adds a rubber stamp annotation (12.5.6.12): a word, such as APPROVED or DRAFT, in a frame with rounded corners.

public PdfMarkupAnnotation AddStamp(PdfRectangle rectangle, string text, PdfColor? color = null)

Parameters

rectangle PdfRectangle
The rectangle of the stamp, in default user space.
text string
The text of the stamp: it is fitted in the rectangle.
color PdfColor?
The color of the stamp, or null for red.

Returns

PdfMarkupAnnotation The annotation. Its /Name is Draft, Approved... when the text is the name of a standard stamp.

Exceptions

ArgumentException
The text is empty, or a character of the text has no glyph in Helvetica Bold.

AddTextMarkup(PdfTextMarkupKind, IEnumerable<PdfRectangle>, PdfColor?, string?)

PdfAnnotationCollection.cs

Adds a text markup annotation (12.5.6.10): a highlight, an underline, a squiggly underline or a strikeout of regions of the page, such as the lines of a text.

public PdfMarkupAnnotation AddTextMarkup(PdfTextMarkupKind kind, IEnumerable<PdfRectangle> regions, PdfColor? color = null, string? text = null)

Parameters

kind PdfTextMarkupKind
The kind of markup.
regions IEnumerable<PdfRectangle>
The regions, in default user space: one rectangle per line of the text, from its baseline to its top.
color PdfColor?
The color, or null for yellow (a highlight) or red.
text string?
The text of the annotation (a comment), or null.

Returns

PdfMarkupAnnotation The annotation. Its appearance is drawn with the color; a highlight is multiplied with the content, so that the text stays readable.

Exceptions

ArgumentException
There is no region.

Returns an enumerator over the annotations.

public IEnumerator<PdfAnnotation> GetEnumerator()

Returns

IEnumerator<PdfAnnotation> The enumerator.

Remove(PdfAnnotation)

PdfAnnotationCollection.cs

Removes an annotation from the page, with the references that would keep it in a saved file: its pop-up annotation, the /IRT and /Popup entries of the other annotations of the page that point to it, the object references of the structure tree, and, for a widget, its entry in its form field.

public bool Remove(PdfAnnotation annotation)

Parameters

annotation PdfAnnotation
The annotation.

Returns

bool true when the annotation was on the page.

System.Collections.IEnumerable.GetEnumerator()

PdfAnnotationCollection.cs
IEnumerator IEnumerable.GetEnumerator()

No documentation is available.