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
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.
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.
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.
System.Collections.IEnumerable.GetEnumerator()

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.

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.

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.

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.