GdPicture.NET.14.API
GdPicture14 Namespace / GdPicturePDF Class / GetFormFieldRequired Method
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.
Example





In This Topic
GetFormFieldRequired Method (GdPicturePDF)
In This Topic
Returns, if the Required flag of a required form field is set. The form field is specified by its unique form field's identifier and it is related to the currently loaded PDF document.

If this flag is set, then the field must have a value at the time it is exported by a submit-form action. Unfortunately the GdPicturePDF doesn't support this feature yet.

Syntax
'Declaration
 
Public Function GetFormFieldRequired( _
   ByVal FieldId As Integer _
) As Boolean
public bool GetFormFieldRequired( 
   int FieldId
)
public function GetFormFieldRequired( 
    FieldId: Integer
): Boolean; 
public function GetFormFieldRequired( 
   FieldId : int
) : boolean;
public: bool GetFormFieldRequired( 
   int FieldId
) 
public:
bool GetFormFieldRequired( 
   int FieldId
) 

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.

Return Value

true if the Required flag of the specified form field is set, otherwise false. The GdPicturePDF.GetStat method can be subsequently used to determine if this method has been successful.
Remarks
This method is only allowed for use with non-encrypted documents.

It is recommend to use the GdPicturePDF.GetStat method to identify the specific reason for the method's failure, if any.

Just to remind you, that the GdPicturePDF class doesn't support the submit-form action yet.

Example
How to determine, which form fields are required in the current document.
Dim caption As String = "Example: GetFormFieldRequired"
Dim gdpicturePDF As GdPicturePDF = New GdPicturePDF()
If gdpicturePDF.LoadFromFile("forms.pdf", False) = 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 does not contain any forms."
        Else
            Dim formID As Integer = 0
            Dim title As String = "", messageRO As String = "ReadOnly fields:" + vbCrLf, messageREQ As String = "Required fields:" + vbCrLf
            Dim roFlag As Boolean = False, reqFlag As Boolean = False
            For i As Integer = 0 To count - 1
                formID = gdpicturePDF.GetFormFieldId(i)
                If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                    title = gdpicturePDF.GetFormFieldTitle(formID)
                    If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                        roFlag = gdpicturePDF.GetFormFieldReadOnly(formID)
                        If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                            If roFlag Then messageRO = messageRO + title + "; "
                        Else
                            message = message + title + ": GetFormFieldReadOnly - " + gdpicturePDF.GetStat().ToString() + vbCrLf
                        End If
                        reqFlag = gdpicturePDF.GetFormFieldRequired(formID)
                        If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                            If reqFlag Then messageREQ = messageREQ + title + "; "
                        Else
                            message = message + title + ": GetFormFieldRequired - " + gdpicturePDF.GetStat().ToString() + vbCrLf
                        End If
                    Else
                        message = message + i.ToString() + ": The GetFormFieldTitle() method has failed with the status: " + gdpicturePDF.GetStat().ToString() + vbCrLf
                    End If
                Else
                    message = message + i.ToString() + ": The GetFormFieldId() method has failed with the status: " + gdpicturePDF.GetStat().ToString() + vbCrLf
                End If
            Next
            message = messageRO + vbCrLf + vbCrLf + messageREQ + vbCrLf + vbCrLf + message + vbCrLf + "Done!"
        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: GetFormFieldRequired";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
if (gdpicturePDF.LoadFromFile("forms.pdf", false) == GdPictureStatus.OK)
{
    int count = gdpicturePDF.GetFormFieldsCount();
    if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
    {
        string message = "";
        if (count == 0)
            message = "This document does not contain any forms.";
        else
        {
            int formID = 0;
            string title = "", messageRO = "ReadOnly fields:\n", messageREQ = "Required fields:\n";
            bool roFlag = false, reqFlag = false;
            for (int i = 0; i < count; i++)
            {
                formID = gdpicturePDF.GetFormFieldId(i);
                if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                {
                    title = gdpicturePDF.GetFormFieldTitle(formID);
                    if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                    {
                        roFlag = gdpicturePDF.GetFormFieldReadOnly(formID);
                        if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                        {
                            if (roFlag)
                                messageRO = messageRO + title + "; ";
                        }
                        else
                            message = message + title + ": GetFormFieldReadOnly - " + gdpicturePDF.GetStat().ToString() + "\n";
            
                        reqFlag = gdpicturePDF.GetFormFieldRequired(formID);
                        if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                        {
                            if (reqFlag)
                                messageREQ = messageREQ + title + "; ";
                        }
                        else
                            message = message + title + ": GetFormFieldRequired - " + gdpicturePDF.GetStat().ToString() + "\n";
                    }
                    else
                        message = message + i.ToString() + ": The GetFormFieldTitle() method has failed with the status: " + gdpicturePDF.GetStat().ToString() + "\n";
                }
                else
                    message = message + i.ToString() + ": The GetFormFieldId() method has failed with the status: " + gdpicturePDF.GetStat().ToString() + "\n";
            }
            message = messageRO + "\n\n" + messageREQ + "\n\n" + message + "\nDone!";
        }
        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