GdPicture.NET.14.API
GdPicture14 Namespace / AnnotationManager Class / GetAnnotationXML 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 AnnotationManager.GetAnnotationCount-1.
Example





In This Topic
GetAnnotationXML Method (AnnotationManager)
In This Topic
Saves the annotation data of the required GdPicture/XMP annotation object, that is specified by its index related to the selected page of the handled document, to an XML formatted string. You can subsequently use the AnnotationManager.AddAnnotationFromXML method to add the exactly same annotation wherever you need.

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

Syntax
'Declaration
 
Public Function GetAnnotationXML( _
   ByVal AnnotationIdx As Integer _
) As String
public string GetAnnotationXML( 
   int AnnotationIdx
)
public function GetAnnotationXML( 
    AnnotationIdx: Integer
): String; 
public function GetAnnotationXML( 
   AnnotationIdx : int
) : String;
public: string* GetAnnotationXML( 
   int AnnotationIdx
) 
public:
String^ GetAnnotationXML( 
   int AnnotationIdx
) 

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 AnnotationManager.GetAnnotationCount-1.

Return Value

A string containing the annotation definition in XML format. The AnnotationManager.GetStat method can be subsequently used to determine if this method has been successful.
Remarks
It is recommend to use the AnnotationManager.GetStat method to identify the specific reason for the method's failure, if any.

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.

Example
How to get an annotation data as an XML formatted string.
Dim status As GdPictureStatus = GdPictureStatus.OK
Dim annotationManager As AnnotationManager = New AnnotationManager()
If (annotationManager.InitFromFile("source.pdf") = GdPictureStatus.OK) AndAlso
   (annotationManager.PageCount > 0) AndAlso (annotationManager.SelectPage(1) = GdPictureStatus.OK) Then
    Dim annotXML As String = ""
    Dim stamp As GdPicture14.Annotations.AnnotationRubberStamp = annotationManager.AddRubberStampAnnot(Color.Red, 0.5F, 0.5F, 2, 1, "APPROVED")
    If stamp IsNot Nothing Then
        stamp.Rotation = 20
        If annotationManager.SaveAnnotationsToPage() = GdPictureStatus.OK Then
            Dim annotIdx As Integer = annotationManager.GetAnnotationIdx(stamp)
            If annotationManager.GetStat() = GdPictureStatus.OK Then
                annotXML = annotationManager.GetAnnotationXML(annotIdx)
                If annotationManager.GetStat() = GdPictureStatus.OK Then
                    status = annotationManager.SaveDocumentToPDF("source_stamped.pdf")
                End If
            Else
                status = annotationManager.GetStat()
            End If
        Else
            status = annotationManager.GetStat()
        End If
        stamp.Dispose()
    End If
    annotationManager.Close()
    If status = GdPictureStatus.OK Then
        If (annotationManager.InitFromFile("dest.pdf") = GdPictureStatus.OK) AndAlso
           (annotationManager.PageCount > 0) AndAlso (annotationManager.SelectPage(1) = GdPictureStatus.OK) Then
            Dim annot As GdPicture14.Annotations.Annotation = annotationManager.AddAnnotationFromXML(annotXML)
            If annot IsNot Nothing Then status = annotationManager.SaveAnnotationsToPage()
            If status = GdPictureStatus.OK Then
                status = annotationManager.SaveDocumentToPDF("dest_stamped.pdf")
            End If
        Else
            status = annotationManager.GetStat()
        End If
    End If
    annotationManager.Close()
Else
    status = annotationManager.GetStat()
End If
If status = GdPictureStatus.OK Then
    MessageBox.Show("Done!", "AnnotationManager.GetAnnotationIdx")
Else
    MessageBox.Show("Error!   Status: " + annotationManager.GetStat().ToString(), "AnnotationManager.GetAnnotationIdx")
End If
annotationManager.Dispose()
GdPictureStatus status = GdPictureStatus.OK;
AnnotationManager annotationManager = new AnnotationManager();
if ((annotationManager.InitFromFile("source.pdf") == GdPictureStatus.OK) &&
    (annotationManager.PageCount > 0) && (annotationManager.SelectPage(1) == GdPictureStatus.OK))
{
    string annotXML = "";
    GdPicture14.Annotations.AnnotationRubberStamp stamp = annotationManager.AddRubberStampAnnot(Color.Red, 0.5f, 0.5f, 2, 1, "APPROVED");
    if (stamp != null)
    {
        stamp.Rotation = 20;
        if (annotationManager.SaveAnnotationsToPage() == GdPictureStatus.OK)
        {
            int annotIdx = annotationManager.GetAnnotationIdx(stamp);
            if (annotationManager.GetStat() == GdPictureStatus.OK)
            {
                annotXML = annotationManager.GetAnnotationXML(annotIdx);
                if (annotationManager.GetStat() == GdPictureStatus.OK)
                    status = annotationManager.SaveDocumentToPDF("source_stamped.pdf");
            }
            else status = annotationManager.GetStat();
        }
        else status = annotationManager.GetStat();
        stamp.Dispose();
    }
    annotationManager.Close();
    if (status == GdPictureStatus.OK)
    {
        if ((annotationManager.InitFromFile("dest.pdf") == GdPictureStatus.OK) &&
            (annotationManager.PageCount > 0) && (annotationManager.SelectPage(1) == GdPictureStatus.OK))
        {
            GdPicture14.Annotations.Annotation annot = annotationManager.AddAnnotationFromXML(annotXML);
            if (annot != null)
                status = annotationManager.SaveAnnotationsToPage();
            if (status == GdPictureStatus.OK)
                status = annotationManager.SaveDocumentToPDF("dest_stamped.pdf");
        }
        else status = annotationManager.GetStat();
    }
    annotationManager.Close();
}
else status = annotationManager.GetStat();
if (status == GdPictureStatus.OK)
    MessageBox.Show("Done!", "AnnotationManager.GetAnnotationXML");
else
    MessageBox.Show("Error!   Status: " + annotationManager.GetStat().ToString(), "AnnotationManager.GetAnnotationXML");
annotationManager.Dispose();
See Also