Get PDF Annotation Properties in C# .NET

To get a PDF’s annotation properties, use one of the following methods:

  • GetAnnotationActionID — Returns the action’s ID associated with the annotation.

  • GetAnnotationColor — Returns a GdPictureColor object that specifies the annotation’s color.

  • GetAnnotationContents — Returns a string value of the annotation’s content. For some annotation types, it returns the annotation’s description.

  • GetAnnotationFillColor — Returns a GdPictureColor object that specifies the interior color of the annotation. It can be used for geometric type annotations such as square, circle, line, or polygon annotations.

  • GetAnnotationFlags — Returns a bitwise combination of the flags set for the annotation. The values are represented as members of the PdfAnnotationFlag enumeration.

  • GetAnnotationName — Returns the annotation name.

  • GetAnnotationOpacity — Returns the opacity value of the annotation.

  • GetAnnotationQuadPoints — Returns the QuadPoints property of the annotation. This method is only applicable for link, highlight, underline, squiggly, and strikeout annotation types.

  • GetAnnotationRect — Returns the bounding box coordinates of the upper-left corner, its width, and its height. Those values depend on the specified origin of the coordinate system and the declared measurement unit used.

  • GetAnnotationSubject — Returns the annotation subject.

  • GetAnnotationSubType — Returns the annotation subtype as a string value.

  • GetAnnotationTitle — Returns the annotation title.

  • GetAnnotationType — This method always returns the Annot value for annotations. Use the GetAnnotationSubType method to get the specific annotation subtype.

Information

All these methods require the annotation index as their parameter and sometimes may require reference parameters.

The methods listed above are helpful when searching for an annotation on which you want to perform other operations. The code example below shows how to find a text annotation using the GetAnnotationTitle method and change its content:

using GdPicturePDF gdpicturePDF = new GdPicturePDF();
gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");
// Select the PDF page.
gdpicturePDF.SelectPage(1);
// Get the annotation count.
int annotCount = gdpicturePDF.GetAnnotationCount();
// Loop through all annotations.
for (int i = 0; i < annotCount; i++)
{
    // Check if the current annotation is of the `FreeText` type.
    if (gdpicturePDF.GetAnnotationSubType(i) == "FreeText")
    {
        // Change the annotation content.
        gdpicturePDF.SetAnnotationContents(i, "New content");
    }
}
gdpicturePDF.SaveToFile(@"C:\temp\output.pdf");
Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    gdpicturePDF.LoadFromFile("C:\temp\source.pdf")
    ' Select the PDF page.
    gdpicturePDF.SelectPage(1)
    ' Get the annotation count.
    Dim annotCount As Integer = gdpicturePDF.GetAnnotationCount()
    ' Loop through all annotations.
    For i = 0 To annotCount - 1
        ' Check if the current annotation is of the `FreeText` type.
        If gdpicturePDF.GetAnnotationSubType(i) Is "FreeText" Then
            ' Change the annotation content.
            gdpicturePDF.SetAnnotationContents(i, "New content")
        End If
    Next
    gdpicturePDF.SaveToFile("C:\temp\output.pdf")
End Using
Used Methods

Related Topics