A unique form field 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.
A string representation of the new current value of the specified form field.
Example





In This Topic
GdPicture14 Namespace / GdPicturePDF Class / SetFormFieldValue Method / SetFormFieldValue(Int32,String) Method

SetFormFieldValue(Int32,String) Method

In This Topic
Sets the current value of a required form field, that is specified by its unique form field's identifier and it is related to the currently loaded PDF document. The value's format varies depending on the type of the form field. This method sets the string representation of the field's current value.
Syntax
'Declaration

 

Public Overloads Function SetFormFieldValue( _

   ByVal FieldId As Integer, _

   ByVal Value As String _

) As GdPictureStatus
public GdPictureStatus SetFormFieldValue( 

   int FieldId,

   string Value

)
public function SetFormFieldValue( 

    FieldId: Integer;

    Value: String

): GdPictureStatus; 
public function SetFormFieldValue( 

   FieldId : int,

   Value : String

) : GdPictureStatus;
public: GdPictureStatus SetFormFieldValue( 

   int FieldId,

   string* Value

) 
public:

GdPictureStatus SetFormFieldValue( 

   int FieldId,

   String^ Value

) 

Parameters

FieldId
A unique form field 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.
Value
A string representation of the new current value of the specified form field.

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.

Just to inform you, that for list boxes allowing multiple selections you need to use the GdPicturePDF.SetFormFieldValue method.

Example
How to set a newly defined value to the required text form field.
Dim caption As String = "Example: SetFormFieldValue"

Dim gdpicturePDF As GdPicturePDF = New GdPicturePDF()

'Please use the PDF document created using the example from the SetFormFieldReadOnly() method.

Dim filename As String = "forms_textfield.pdf"

If gdpicturePDF.LoadFromFile(filename, True) = GdPictureStatus.OK Then

    Dim count As Integer = gdpicturePDF.GetFormFieldsCount()

    If gdpicturePDF.GetStat() = GdPictureStatus.OK Then

        Dim message As String = ""

        If count = 0 Then message = "This document doesn't contain form fields."

        Dim formID As Integer = 0, formIDFile As Integer = 0, formIDCode As Integer = 0

        Dim name As String = ""

        For i As Integer = 0 To count - 1

            formID = gdpicturePDF.GetFormFieldId(i)

            If gdpicturePDF.GetStat() = GdPictureStatus.OK Then

                name = gdpicturePDF.GetFormFieldTitle(formID)

                If gdpicturePDF.GetStat() = GdPictureStatus.OK Then

                    If name.Equals("Filename") Then formIDFile = formID

                    If name.Equals("Code snippet") Then formIDCode = formID

                Else

                    message = "The GetFormFieldTitle() method has failed with the status: " + gdpicturePDF.GetStat().ToString()

                    Exit For

                End If

            Else

                message = "The GetFormFieldId() method has failed with the status: " + gdpicturePDF.GetStat().ToString()

                Exit For

            End If

        Next

        If (count <> 0) AndAlso (gdpicturePDF.GetStat() = GdPictureStatus.OK) Then

            Dim value As String = gdpicturePDF.GetFormFieldValue(formIDFile)

            If gdpicturePDF.GetStat() = GdPictureStatus.OK Then

                If Not value.Equals("") Then

                    Dim reader As StreamReader = New StreamReader(value)

                    Dim content As String = reader.ReadToEnd()

                    If gdpicturePDF.SetFormFieldValue(formIDCode, content) = GdPictureStatus.OK Then

                        If gdpicturePDF.SaveToFile(filename) = GdPictureStatus.OK Then

                            message = "The example has been followed successfully and the file has been saved."

                        Else

                            message = "The example has been followed successfully, but the file can't be saved. Status: " + gdpicturePDF.GetStat().ToString()

                        End If

                    Else

                        message = "The SetFormFieldValue() method has failed with the status: " + gdpicturePDF.GetStat().ToString()

                    End If

                    reader.Dispose()

                Else

                    message = "The expected filename with the code snippet is not specified."

                End If

            Else

                message = "The GetFormFieldValue() method has failed with the status: " + gdpicturePDF.GetStat().ToString()

            End If

        End If

        MessageBox.Show(message, caption)

    Else

        MessageBox.Show("The GetFormFieldsCount() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)

    End If

Else

    MessageBox.Show("The file can't be loaded.", caption)

End If

gdpicturePDF.Dispose()
string caption = "Example: SetFormFieldValue";

GdPicturePDF gdpicturePDF = new GdPicturePDF();

//Please use the PDF document created using the example from the SetFormFieldReadOnly() method.

string filename = "forms_textfield.pdf";

if (gdpicturePDF.LoadFromFile(filename, true) == GdPictureStatus.OK)

{

    int count = gdpicturePDF.GetFormFieldsCount();

    if (gdpicturePDF.GetStat() == GdPictureStatus.OK)

    {

        string message = "";

        if (count == 0) message = "This document doesn't contain form fields.";

        int formID = 0, formIDFile = 0, formIDCode = 0;

        string name = "";

        for (int i = 0; i < count; i++)

        {

            formID = gdpicturePDF.GetFormFieldId(i);

            if (gdpicturePDF.GetStat() == GdPictureStatus.OK)

            {

                name = gdpicturePDF.GetFormFieldTitle(formID);

                if (gdpicturePDF.GetStat() == GdPictureStatus.OK)

                {

                    if (name.Equals("Filename"))

                        formIDFile = formID;

                    if (name.Equals("Code snippet"))

                        formIDCode = formID;

                }

                else

                {

                    message = "The GetFormFieldTitle() method has failed with the status: " + gdpicturePDF.GetStat().ToString();

                    break;

                }

            }

            else

            {

                message = "The GetFormFieldId() method has failed with the status: " + gdpicturePDF.GetStat().ToString();

                break;

            }

        }

        if ((count != 0) && (gdpicturePDF.GetStat() == GdPictureStatus.OK))

        {

            string value = gdpicturePDF.GetFormFieldValue(formIDFile);

            if (gdpicturePDF.GetStat() == GdPictureStatus.OK)

            {

                if (!value.Equals(""))

                {

                    StreamReader reader = new StreamReader(value);

                    string content = reader.ReadToEnd();

                    if (gdpicturePDF.SetFormFieldValue(formIDCode, content) == GdPictureStatus.OK)

                    {

                        if (gdpicturePDF.SaveToFile(filename) == GdPictureStatus.OK)

                            message = "The example has been followed successfully and the file has been saved.";

                        else

                            message = "The example has been followed successfully, but the file can't be saved. Status: " + gdpicturePDF.GetStat().ToString();

                    }

                    else

                        message = "The SetFormFieldValue() method has failed with the status: " + gdpicturePDF.GetStat().ToString();

                    reader.Dispose();

                }

                else

                    message = "The expected filename with the code snippet is not specified.";

            }

            else

                message = "The GetFormFieldValue() method has failed with the status: " + gdpicturePDF.GetStat().ToString();

            

        }

        MessageBox.Show(message, caption);

    }

    else

        MessageBox.Show("The GetFormFieldsCount() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);

}

else

    MessageBox.Show("The file can't be loaded.", caption);

gdpicturePDF.Dispose();
See Also