A properly formatted string containing the annotation definition in XML format.
Example





In This Topic
GdPicture14 Namespace / AnnotationManager Class / AddAnnotationFromXML Method

AddAnnotationFromXML Method (AnnotationManager)

In This Topic
Adds a new GdPicture/XMP annotation from an XML definition on the selected page of the document currently handled by this AnnotationManager object. You can use the GetAnnotationXML method to obtain an annotation XML data.

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

Syntax
'Declaration

 

Public Function AddAnnotationFromXML( _

   ByVal XML As String _

) As Annotation
public Annotation AddAnnotationFromXML( 

   string XML

)
public function AddAnnotationFromXML( 

    XML: String

): Annotation; 
public function AddAnnotationFromXML( 

   XML : String

) : Annotation;
public: Annotation* AddAnnotationFromXML( 

   string* XML

) 
public:

Annotation^ AddAnnotationFromXML( 

   String^ XML

) 

Parameters

XML
A properly formatted string containing the annotation definition in XML format.

Return Value

A GdPicture/XMP Annotation object. The newly added GdPicture/XMP annotation.
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.

You can regularly apply the GetStat method to determine if this method has been successful.

Example
How to add an annotation from previously initialized XML 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.AddAnnotationFromXML");

else

    MessageBox.Show("Error!   Status: " + annotationManager.GetStat().ToString(), "AnnotationManager.AddAnnotationFromXML");

annotationManager.Dispose();
See Also