PdfAnnotationCollection Class
The annotations of a page: the /Annots array (ISO 32000-2, 12.5).
public sealed class PdfAnnotationCollection : IEnumerable<PdfAnnotation>, IReadOnlyCollection<PdfAnnotation>, IReadOnlyList<PdfAnnotation>, IEnumerableRemarks
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
| Name | Description |
|---|---|
| Count | Gets the number of annotations. |
Indexers
| Name | Description |
|---|---|
| this[int] | Gets an annotation. |
this[int]
PdfAnnotationCollection.csGets an annotation.
public PdfAnnotation this[int index] { get; }Methods
| Name | Description |
|---|---|
| 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.csAdds a file attachment annotation (12.5.6.15) that holds a file of the document, such as a file of PdfDocument.EmbeddedFiles.
public PdfFileAttachmentAnnotation AddFileAttachment(PdfRectangle rectangle, PdfEmbeddedFile file, PdfFileAttachmentIcon icon = PdfFileAttachmentIcon.PushPin)Parameters
rectanglePdfRectangle- The region of the icon, in default user space.
filePdfEmbeddedFile- The file.
iconPdfFileAttachmentIcon- 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.csAdds 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
rectanglePdfRectangle- The region of the icon, in default user space.
fileNamestring- The name of the file.
dataReadOnlySpan<byte>- The content of the file.
optionsPdfEmbeddedFileOptions?- The attributes of the file, or
nullfor the defaults. iconPdfFileAttachmentIcon- 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
ArgumentExceptionfileNameis empty, or the MIME type is not valid.
AddFreeText(PdfRectangle, string, PdfStandardFont, double, PdfColor?)
PdfAnnotationCollection.csAdds 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
rectanglePdfRectangle- The box, in default user space.
textstring- The text: it is broken into lines that fit the box.
fontPdfStandardFont- The font, a standard font: the default appearance string of the annotation (
/DA) names it. fontSizedouble- The font size.
colorPdfColor?- The color of the text and of the border, or
nullfor black.
Returns
PdfMarkupAnnotation The annotation.
Exceptions
ArgumentException- A character of the text has no glyph in the font.
AddLink overloads
AddLink(PdfRectangle, PdfDestination)
PdfAnnotationCollection.csAdds a link that goes to a destination of the document.
public PdfLinkAnnotation AddLink(PdfRectangle rectangle, PdfDestination destination)Parameters
rectanglePdfRectangle- The region of the page, in default user space.
destinationPdfDestination- The destination.
Returns
PdfLinkAnnotation The link.
AddLink(PdfRectangle, Uri)
PdfAnnotationCollection.csAdds a link that opens a URI.
public PdfLinkAnnotation AddLink(PdfRectangle rectangle, Uri uri)Parameters
rectanglePdfRectangle- The region of the page, in default user space.
uriUri- The URI: an absolute URI, written as 7-bit ASCII (12.6.4.8): an internationalized host in its IDNA ASCII form (
xn--labels), the other non-ASCII characters percent-encoded as UTF-8.
Returns
PdfLinkAnnotation The link.
AddNote(PdfPoint, string, PdfColor?)
PdfAnnotationCollection.csAdds 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
positionPdfPoint- The lower-left corner of the icon, in default user space; the icon is 20 x 20.
textstring- The text of the note.
colorPdfColor?- The color of the icon, or
nullfor yellow.
Returns
PdfMarkupAnnotation The note.
AddStamp(PdfRectangle, string, PdfColor?)
PdfAnnotationCollection.csAdds 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
rectanglePdfRectangle- The rectangle of the stamp, in default user space.
textstring- The text of the stamp: it is fitted in the rectangle.
colorPdfColor?- The color of the stamp, or
nullfor 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.csAdds 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
kindPdfTextMarkupKind- The kind of markup.
regionsIEnumerable<PdfRectangle>- The regions, in default user space: one rectangle per line of the text, from its baseline to its top.
colorPdfColor?- The color, or
nullfor yellow (a highlight) or red. textstring?- 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.
GetEnumerator()
PdfAnnotationCollection.csReturns an enumerator over the annotations.
public IEnumerator<PdfAnnotation> GetEnumerator()Returns
IEnumerator<PdfAnnotation> The enumerator.
Remove(PdfAnnotation)
PdfAnnotationCollection.csRemoves an annotation from the page.
public bool Remove(PdfAnnotation annotation)Parameters
annotationPdfAnnotation- The annotation.
Returns
bool true when the annotation was on the page.