GdPicture.NET.14
GdPicture14 Namespace / AnnotationManager Class / SetAnnotationPropertyValue Method
The 0-based index of the required annotation within the selected page of the handled document. It must be a value from 0 to GetAnnotationCount-1.
The name of a required annotation property as a string, for example, "FillColor".
The new value to apply for the specified annotation property.
Example





In This Topic
SetAnnotationPropertyValue Method (AnnotationManager)
In This Topic
Changes the current value of an annotation property, which is defined by its name, to a newly specified value. The GdPicture/XMP annotation object is specified by its index and relates to the selected page of the document currently handled by this AnnotationManager object.

This method has been initially introduced for the COM interop edition. Please refer to the Annotations Namespace for the .NET edition to determine available annotation properties and explore them for each particular class. All annotations classes share their properties from the main Annotation class and add their own properties to the individual classes according to the annotation type.

Be aware that this method only handles GdPicture/XMP annotations. Likewise, annotations are always treated relative to the selected page.

Syntax
'Declaration
 
Public Function SetAnnotationPropertyValue( _
   ByVal AnnotationIdx As Integer, _
   ByVal Name As String, _
   ByVal Value As Object _
) As GdPictureStatus
public GdPictureStatus SetAnnotationPropertyValue( 
   int AnnotationIdx,
   string Name,
   object Value
)
public function SetAnnotationPropertyValue( 
    AnnotationIdx: Integer;
    Name: String;
    Value: TObject
): GdPictureStatus; 
public function SetAnnotationPropertyValue( 
   AnnotationIdx : int,
   Name : String,
   Value : Object
) : GdPictureStatus;
public: GdPictureStatus SetAnnotationPropertyValue( 
   int AnnotationIdx,
   string* Name,
   Object* Value
) 
public:
GdPictureStatus SetAnnotationPropertyValue( 
   int AnnotationIdx,
   String^ Name,
   Object^ Value
) 

Parameters

AnnotationIdx
The 0-based index of the required annotation within the selected page of the handled document. It must be a value from 0 to GetAnnotationCount-1.
Name
The name of a required annotation property as a string, for example, "FillColor".
Value
The new value to apply for the specified annotation property.

Return Value

A member of the GdPictureStatus enumeration. If the method has been successfully followed, then the return value is GdPictureStatus.OK. We strongly recommend always checking this status first.
Remarks
Please ensure that you have selected the proper page before starting any annotation related action with the handled document. Annotations are always treated relative to the currently selected page.

At the same, be aware that the method only handles GdPicture/XMP annotations.

Example
How to set the value of the required property of the specified annotation.
Using annotationManager As AnnotationManager = New AnnotationManager()
    If annotationManager.InitFromFile("source.pdf") = GdPictureStatus.OK Then
        For p As Integer = 1 To annotationManager.PageCount
            If annotationManager.SelectPage(p) = GdPictureStatus.OK Then
                Dim annotCount As Integer = annotationManager.GetAnnotationCount()
                If annotationManager.GetStat() = GdPictureStatus.OK Then
                    For a As Integer = 0 To annotCount - 1
                        Dim value As Object = annotationManager.GetAnnotationPropertyValue(a, "Tag")
                        Dim tagValue As String = ""
                        If value IsNot Nothing Then
                            tagValue = CStr(value)
                            If tagValue.Equals("delete") Then
                                If annotationManager.DeleteAnnotation(a) <> GdPictureStatus.OK Then Exit For
                            Else
                                tagValue += " checked"
                                value = CObj(tagValue)
                                If annotationManager.SetAnnotationPropertyValue(a, "Tag", value) <> GdPictureStatus.OK Then Exit For
                            End If
                        End If
                    Next
                    If annotationManager.GetStat() = GdPictureStatus.OK Then annotationManager.SaveAnnotationsToPage()
                    If annotationManager.GetStat() <> GdPictureStatus.OK Then Exit For
                Else
                    Exit For
                End If
            Else
                Exit For
            End If
        Next
        If annotationManager.GetStat() = GdPictureStatus.OK Then
            If annotationManager.SaveDocumentToPDF("dest.pdf") = GdPictureStatus.OK Then
                MessageBox.Show("Done!", "AnnotationManager.SetAnnotationPropertyValue")
            Else
                MessageBox.Show("The document can't be saved. Status: " + annotationManager.GetStat().ToString(), "AnnotationManager.SetAnnotationPropertyValue")
            End If
        Else
            MessageBox.Show("Error!   Status: " + annotationManager.GetStat().ToString(), "AnnotationManager.SetAnnotationPropertyValue")
        End If
        annotationManager.Close()
    Else
        MessageBox.Show("The AnnotationManager can't be properly initialized. Status: " + annotationManager.GetStat().ToString(), "AnnotationManager.SetAnnotationPropertyValue")
    End If
End Using
using (AnnotationManager annotationManager = new AnnotationManager())
{
    if (annotationManager.InitFromFile("source.pdf") == GdPictureStatus.OK)
    {
        for (int p = 1; p <= annotationManager.PageCount; p++)
        {
            if (annotationManager.SelectPage(p) == GdPictureStatus.OK)
            {
                int annotCount = annotationManager.GetAnnotationCount();
                if (annotationManager.GetStat() == GdPictureStatus.OK)
                {
                    for (int a = 0; a < annotCount; a++)
                    {
                        object value = annotationManager.GetAnnotationPropertyValue(a, "Tag");
                        string tagValue = "";
                        if (value != null)
                        {
                            tagValue = (string)value;
                            if (tagValue.Equals("delete"))
                            {
                                if (annotationManager.DeleteAnnotation(a) != GdPictureStatus.OK) break;
                            }
                            else
                            {
                                tagValue += " checked";
                                value = (object)tagValue;
                                if (annotationManager.SetAnnotationPropertyValue(a, "Tag", value) != GdPictureStatus.OK) break;
                            }
                        }
                    }
                    if (annotationManager.GetStat() == GdPictureStatus.OK)
                        annotationManager.SaveAnnotationsToPage();
                    if (annotationManager.GetStat() != GdPictureStatus.OK) break;
                }
                else break;
            }
            else break;
        }
        if (annotationManager.GetStat() == GdPictureStatus.OK)
        {
            if (annotationManager.SaveDocumentToPDF("dest.pdf") == GdPictureStatus.OK)
                MessageBox.Show("Done!", "AnnotationManager.SetAnnotationPropertyValue");
            else
                MessageBox.Show("The document can't be saved. Status: " + annotationManager.GetStat().ToString(), "AnnotationManager.SetAnnotationPropertyValue");
        }
        else
            MessageBox.Show("Error!   Status: " + annotationManager.GetStat().ToString(), "AnnotationManager.SetAnnotationPropertyValue");
        annotationManager.Close();
    }
    else
        MessageBox.Show("The AnnotationManager can't be properly initialized. Status: " + annotationManager.GetStat().ToString(), "AnnotationManager.SetAnnotationPropertyValue");
}
See Also