GdPicture.NET.14
GdPicture14 Namespace / GdPicturePDF Class / AttachTagToAnnotation Method
A unique tag identifier of the tag's tree element to be attached to the specified annotation object. You can obtain this identifier using the NewTag method.
The 0-based index of the required annotation within the current page. It must be a value from 0 to GetAnnotationCount-1.
Example





In This Topic
AttachTagToAnnotation Method (GdPicturePDF)
In This Topic
Attaches the defined structure element (tag), that is identified by its unique tag's identifier, to the specified annotation object, that is identified by its index related to the currently selected page of the loaded PDF document. The required structure element (tag) should be a part of the document's tag structure tree.
Syntax
'Declaration
 
Public Function AttachTagToAnnotation( _
   ByVal TagID As Integer, _
   ByVal AnnotationIdx As Integer _
) As GdPictureStatus
public GdPictureStatus AttachTagToAnnotation( 
   int TagID,
   int AnnotationIdx
)
public function AttachTagToAnnotation( 
    TagID: Integer;
    AnnotationIdx: Integer
): GdPictureStatus; 
public function AttachTagToAnnotation( 
   TagID : int,
   AnnotationIdx : int
) : GdPictureStatus;
public: GdPictureStatus AttachTagToAnnotation( 
   int TagID,
   int AnnotationIdx
) 
public:
GdPictureStatus AttachTagToAnnotation( 
   int TagID,
   int AnnotationIdx
) 

Parameters

TagID
A unique tag identifier of the tag's tree element to be attached to the specified annotation object. You can obtain this identifier using the NewTag method.
AnnotationIdx
The 0-based index of the required annotation within the current page. It must be a value from 0 to GetAnnotationCount-1.

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
This method is only allowed for use with non-encrypted documents.
Example
How to attach a newly created tag element to a link annotation.
Dim caption As String = "Example: AttachTagToAnnotation"
Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    If (gdpicturePDF.NewPDF(PdfConformance.PDF_UA_1) = GdPictureStatus.OK) AndAlso
       (gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) = GdPictureStatus.OK) Then
        gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
        'This is required to have a valid PDF_UA document.
        gdpicturePDF.SetTitle("My first PDF/UA document")
        Dim fontResName As String = gdpicturePDF.AddTrueTypeFontU("Arial", False, False, True)
        If (gdpicturePDF.GetStat() = GdPictureStatus.OK) AndAlso
           (gdpicturePDF.SetFillColor(Color.Blue) = GdPictureStatus.OK) AndAlso
           (gdpicturePDF.SetTextSize(16) = GdPictureStatus.OK) Then
            Dim tagRootID As Integer = gdpicturePDF.GetTagRootID()
            If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                Dim linkTagID As Integer = gdpicturePDF.NewTag(tagRootID, "Link")
                If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                    Dim linkAnnotIdx As Integer = gdpicturePDF.AddLinkToWebAnnotation(100, 100, 100, 20, "http://www.gdpicture.com/", False, 0, 0, 255)
                    If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                        If gdpicturePDF.AttachTagToAnnotation(linkTagID, linkAnnotIdx) = GdPictureStatus.OK Then
                            If (gdpicturePDF.BeginMarkedContentSequence(linkTagID, "Span") = GdPictureStatus.OK) AndAlso
                               (gdpicturePDF.DrawTextBox(fontResName, 100, 100, 200, 120, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, "GdPicture") = GdPictureStatus.OK) AndAlso
                               (gdpicturePDF.EndMarkedContent() = GdPictureStatus.OK) Then
                                Dim status As GdPictureStatus = gdpicturePDF.SaveToFile("test_tagged.pdf")
                                If status = GdPictureStatus.OK Then
                                    MessageBox.Show("Your tagged document has been successfully created.", caption)
                                Else
                                    MessageBox.Show("The file can't be saved. Status: " + status.ToString(), caption)
                                End If
                            Else
                                MessageBox.Show("The creation of the marked content sequence has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
                            End If
                        Else
                            MessageBox.Show("The AttachTagToAnnotation() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
                        End If
                    Else
                        MessageBox.Show("The AddLinkToWebAnnotation() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
                    End If
                Else
                    MessageBox.Show("The NewTag() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
                End If
            Else
                MessageBox.Show("The GetTagRootID() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
            End If
        Else
            MessageBox.Show("Setting text properties has failed. Status: " + gdpicturePDF.GetStat().ToString(), caption)
        End If
        gdpicturePDF.CloseDocument()
    Else
        MessageBox.Show("The new document can't be created. Status: " + gdpicturePDF.GetStat().ToString(), caption)
    End If
End Using
string caption = "Example: AttachTagToAnnotation";
using (GdPicturePDF gdpicturePDF = new GdPicturePDF())
{
    if ((gdpicturePDF.NewPDF(PdfConformance.PDF_UA_1) == GdPictureStatus.OK) &&
        (gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) == GdPictureStatus.OK))
    {
        gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
        //This is required to have a valid PDF_UA document.
        gdpicturePDF.SetTitle("My first PDF/UA document");
        string fontResName = gdpicturePDF.AddTrueTypeFontU("Arial", false, false, true);
        if ((gdpicturePDF.GetStat() == GdPictureStatus.OK) &&
            (gdpicturePDF.SetFillColor(Color.Blue) == GdPictureStatus.OK) &&
            (gdpicturePDF.SetTextSize(16) == GdPictureStatus.OK))
        {
            int tagRootID = gdpicturePDF.GetTagRootID();
            if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
            {
                int linkTagID = gdpicturePDF.NewTag(tagRootID, "Link");
                if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                {
                    int linkAnnotIdx = gdpicturePDF.AddLinkToWebAnnotation(100, 100, 100, 20, "http://www.gdpicture.com/", false, 0, 0, 255);
                    if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                    {
                        if (gdpicturePDF.AttachTagToAnnotation(linkTagID, linkAnnotIdx) == GdPictureStatus.OK)
                        {
                            if ((gdpicturePDF.BeginMarkedContentSequence(linkTagID, "Span") == GdPictureStatus.OK) &&
                                (gdpicturePDF.DrawTextBox(fontResName, 100, 100, 200, 120, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, "GdPicture") == GdPictureStatus.OK) &&
                                (gdpicturePDF.EndMarkedContent() == GdPictureStatus.OK))
                            {
                                GdPictureStatus status = gdpicturePDF.SaveToFile("test_tagged.pdf");
                                if (status == GdPictureStatus.OK)
                                    MessageBox.Show("Your tagged document has been successfully created.", caption);
                                else
                                    MessageBox.Show("The file can't be saved. Status: " + status.ToString(), caption);
                            }
                            else
                                MessageBox.Show("The creation of the marked content sequence has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
                        }
                        else
                            MessageBox.Show("The AttachTagToAnnotation() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
                    }
                    else
                        MessageBox.Show("The AddLinkToWebAnnotation() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
                }
                else
                    MessageBox.Show("The NewTag() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
            }
            else
                MessageBox.Show("The GetTagRootID() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
        }
        else
            MessageBox.Show("Setting text properties has failed. Status: " + gdpicturePDF.GetStat().ToString(), caption);
        gdpicturePDF.CloseDocument();
    }
    else
        MessageBox.Show("The new document can't be created. Status: " + gdpicturePDF.GetStat().ToString(), caption);
}
See Also