GdPicture.NET.14.API
GdPicture14 Namespace / GdPicturePDF Class / AttachTagToFormField Method
A unique tag identifier of the tag's tree element to be attached to the specified form field object. You can obtain this identifier using the GdPicturePDF.NewTag method.
A unique form field's identifier specifying a required form field object. You can obtain this identifier using methods like GdPicturePDF.GetFormFieldId, GdPicturePDF.GetFormFieldChildID or methods intended to add form fields.
Example





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

Parameters

TagID
A unique tag identifier of the tag's tree element to be attached to the specified form field object. You can obtain this identifier using the GdPicturePDF.NewTag method.
FieldID
A unique form field's identifier specifying a required form field object. You can obtain this identifier using methods like GdPicturePDF.GetFormFieldId, GdPicturePDF.GetFormFieldChildID or methods intended to add form fields.

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 text form field.
Dim caption As String = "Example: AttachTagToFormField"
Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    Dim message As String = ""
    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, False)
        If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then
            message = "Setting text properties has failed. Status: " + gdpicturePDF.GetStat().ToString()
            GoTo [error]
        End If
        Dim tagRootID As Integer = gdpicturePDF.GetTagRootID()
        If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then
            message = "The GetTagRootID() method has failed. Status: " + gdpicturePDF.GetStat().ToString()
            GoTo [error]
        End If
        'Creating a parent tag of the type 'Div' that will hold both the form field and its caption.
        Dim divTag As Integer = gdpicturePDF.NewTag(tagRootID, "Div")
        If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then
            message = "The NewTag(Div) method has failed. Status: " + gdpicturePDF.GetStat().ToString()
            GoTo [error]
        End If
        'Creating a tag of the type 'Caption'.
        Dim captionTag As Integer = gdpicturePDF.NewTag(divTag, "Caption")
        If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then
            message = "The NewTag(Caption) method has failed. Status: " + gdpicturePDF.GetStat().ToString()
            GoTo [error]
        End If
        'Drawing a caption for the text form field.
        If (gdpicturePDF.BeginMarkedContentSequence(captionTag, "Span") <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.DrawText(fontResName, 100, 70, "Your toolkit is: ") <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.EndMarkedContent() <> GdPictureStatus.OK) Then
            message = "The creation of the marked content sequence has failed. Status: " + gdpicturePDF.GetStat().ToString()
            GoTo [error]
        End If
        'Creating a tag of the type 'Form'.
        Dim formTag As Integer = gdpicturePDF.NewTag(divTag, "Form")
        If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then
            message = "The NewTag(Form) method has failed. Status: " + gdpicturePDF.GetStat().ToString()
            GoTo [error]
        End If
        'Creating a text form field.
        Dim formID As Integer = gdpicturePDF.AddTextFormField(220, 50, 150, 30, "TextField_Name", "GdPicture14", False, fontResName, 20, Color.Brown)
        If (gdpicturePDF.GetStat() <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.SetFormFieldBackgroundColor(formID, Color.White) <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.SetFormFieldBorderColor(formID, Color.Brown) <> GdPictureStatus.OK) Then
            message = "The NewTag(Caption) method has failed. status: " + gdpicturePDF.GetStat().ToString()
            GoTo [error]
        End If
        'Attaching the prepared tag to the new text form field.
        If (gdpicturePDF.AttachTagToFormField(formTag, formID) <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.SetTagTitle(formTag, "Name Field") <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.SetFormFieldAlternateTitle(formID, "Name Field") <> GdPictureStatus.OK) Then
            message = "Attaching the tag to the form field has failed. Status: " + gdpicturePDF.GetStat().ToString()
            GoTo [error]
        End If
        If gdpicturePDF.SaveToFile("test_tagged.pdf") = GdPictureStatus.OK Then
            message = "Your tagged document has been successfully created."
        Else
            message = "The example has been successfully followed, but the SaveToFile() method has failed. Status: " + gdpicturePDF.GetStat().ToString()
        End If
[error]:
        MessageBox.Show(message, caption)
        gdpicturePDF.CloseDocument()
    Else
        MessageBox.Show("The new document can't be created. Status: " + gdpicturePDF.GetStat().ToString(), caption)
    End If
End Using
string caption = "Example: AttachTagToFormField";
using (GdPicturePDF gdpicturePDF = new GdPicturePDF())
{
    string message = "";
    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, false);
        if (gdpicturePDF.GetStat() != GdPictureStatus.OK)
        {
            message = "Setting text properties has failed. Status: " + gdpicturePDF.GetStat().ToString();
            goto error;
        }
        int tagRootID = gdpicturePDF.GetTagRootID();
        if (gdpicturePDF.GetStat() != GdPictureStatus.OK)
        {
            message = "The GetTagRootID() method has failed. Status: " + gdpicturePDF.GetStat().ToString();
            goto error;
        }
        //Creating a parent tag of the type 'Div' that will hold both the form field and its caption.
        int divTag = gdpicturePDF.NewTag(tagRootID, "Div");
        if (gdpicturePDF.GetStat() != GdPictureStatus.OK)
        {
            message = "The NewTag(Div) method has failed. Status: " + gdpicturePDF.GetStat().ToString();
            goto error;
        }
        //Creating a tag of the type 'Caption'.
        int captionTag = gdpicturePDF.NewTag(divTag, "Caption");
        if (gdpicturePDF.GetStat() != GdPictureStatus.OK)
        {
            message = "The NewTag(Caption) method has failed. Status: " + gdpicturePDF.GetStat().ToString();
            goto error;
        }
        //Drawing a caption for the text form field.
        if ((gdpicturePDF.BeginMarkedContentSequence(captionTag, "Span") != GdPictureStatus.OK) ||
            (gdpicturePDF.DrawText(fontResName, 100, 70, "Your toolkit is: ") != GdPictureStatus.OK) ||
            (gdpicturePDF.EndMarkedContent() != GdPictureStatus.OK))
        {
            message = "The creation of the marked content sequence has failed. Status: " + gdpicturePDF.GetStat().ToString();
            goto error;
        }
        //Creating a tag of the type 'Form'.
        int formTag = gdpicturePDF.NewTag(divTag, "Form");
        if (gdpicturePDF.GetStat() != GdPictureStatus.OK)
        {
            message = "The NewTag(Form) method has failed. Status: " + gdpicturePDF.GetStat().ToString();
            goto error;
        }
        //Creating a text form field.
        int formID = gdpicturePDF.AddTextFormField(220, 50, 150, 30, "TextField_Name", "GdPicture14", false, fontResName, 20, Color.Brown);
        if ((gdpicturePDF.GetStat() != GdPictureStatus.OK) ||
            (gdpicturePDF.SetFormFieldBackgroundColor(formID, Color.White) != GdPictureStatus.OK) ||
            (gdpicturePDF.SetFormFieldBorderColor(formID, Color.Brown) != GdPictureStatus.OK))
        {
            message = "The NewTag(Caption) method has failed. status: " + gdpicturePDF.GetStat().ToString();
            goto error;
        }
        //Attaching the prepared tag to the new text form field.
        if ((gdpicturePDF.AttachTagToFormField(formTag, formID) != GdPictureStatus.OK) ||
            (gdpicturePDF.SetTagTitle(formTag, "Name Field") != GdPictureStatus.OK) ||
            (gdpicturePDF.SetFormFieldAlternateTitle(formID, "Name Field") != GdPictureStatus.OK))
        {
            message = "Attaching the tag to the form field has failed. Status: " + gdpicturePDF.GetStat().ToString();
            goto error;
        }
        if (gdpicturePDF.SaveToFile("test_tagged.pdf") == GdPictureStatus.OK)
            message = "Your tagged document has been successfully created.";
        else
            message = "The example has been successfully followed, but the SaveToFile() method has failed. Status: " + gdpicturePDF.GetStat().ToString();
        error:
        MessageBox.Show(message, caption);
        gdpicturePDF.CloseDocument();
    }
    else
        MessageBox.Show("The new document can't be created. Status: " + gdpicturePDF.GetStat().ToString(), caption);
}
See Also