GdPicture.NET.14
GdPicture14 Namespace / GdPicturePDF Class / GetFormFieldMaxLen Method
A unique form field identifier specifying a required form field object. You can obtain this identifier using these methods: AddTextFormField(Single,Single,Single,Single,String,String,Boolean,String,Single,Color) , GetFormFieldId or GetFormFieldChildID.
Example





In This Topic
GetFormFieldMaxLen Method (GdPicturePDF)
In This Topic
Returns the defined maximum length of the field's text, in characters, of a required form field, here a text field. The text field is specified by its unique form field's identifier and it is related to the currently loaded PDF document. As stated, this flag is only specific to text fields, so this method is explicitly applicable to text form field objects.
Syntax
'Declaration
 
Public Function GetFormFieldMaxLen( _
   ByVal FieldId As Integer _
) As Integer
public int GetFormFieldMaxLen( 
   int FieldId
)
public function GetFormFieldMaxLen( 
    FieldId: Integer
): Integer; 
public function GetFormFieldMaxLen( 
   FieldId : int
) : int;
public: int GetFormFieldMaxLen( 
   int FieldId
) 
public:
int GetFormFieldMaxLen( 
   int FieldId
) 

Parameters

FieldId
A unique form field identifier specifying a required form field object. You can obtain this identifier using these methods: AddTextFormField(Single,Single,Single,Single,String,String,Boolean,String,Single,Color) , GetFormFieldId or GetFormFieldChildID.

Return Value

The maximum length of the field's text, in characters, of the specified text field. The 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 GetStat method to identify the specific reason for the method's failure, if any.

Just to remind you that this method is only meaningful for text fields, otherwise it will fail.

Example
How to utilize the MaxLen attribute to check the input values of the text form fields, which represent the different postal codes.
Dim caption As String = "Example: GetFormFieldMaxLen"
Dim gdpicturePDF As GdPicturePDF = New GdPicturePDF()
'Please use the PDF document created using the example from the SetFormFieldMaxLen() method.
If gdpicturePDF.LoadFromFile("forms_textfield.pdf", False) = GdPictureStatus.OK Then
    Dim count As Integer = gdpicturePDF.GetFormFieldsCount()
    If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
        Dim message As String = "", value As String = ""
        If count = 0 Then message = "This document does not contain any forms."
        Dim formID As Integer = 0, maxLen As Integer = 0, j As Integer = 0
        Dim comb As Boolean = False
        Dim type As PdfFormFieldType = PdfFormFieldType.PdfFormFieldTypeUnknown
        For i As Integer = 0 To count - 1
            formID = gdpicturePDF.GetFormFieldId(i)
            If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                type = gdpicturePDF.GetFormFieldType(formID)
                If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                    If type = PdfFormFieldType.PdfFormFieldTypeText Then
                        j += 1
                        comb = gdpicturePDF.GetFormFieldComb(formID)
                        If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                            maxLen = gdpicturePDF.GetFormFieldMaxLen(formID)
                            If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                                value = gdpicturePDF.GetFormFieldValue(formID)
                                If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                                    If comb Then
                                        If (value.Length = maxLen) AndAlso (Not value.Contains(" ")) Then
                                            message = message + "The " + j.ToString() + ".text field holds the CORRECT value = " + value + vbCrLf
                                        Else
                                            message = message + "The " + j.ToString() + ".text field holds the INCORRECT value = " + value + vbCrLf
                                        End If
                                    Else
                                        message = message + "The " + j.ToString() + ".text field has not set the Comb flag. Its value is " + value + "." + vbCrLf
                                    End If
                                Else
                                    message = message + "The GetFormFieldValue() method has failed with the status: " + gdpicturePDF.GetStat().ToString()
                                    Exit For
                                End If
                            Else
                                message = message + "The GetFormFieldMaxLen() method has failed with the status: " + gdpicturePDF.GetStat().ToString()
                                Exit For
                            End If
                        Else
                            message = message + "The GetFormFieldComb() method has failed with the status: " + gdpicturePDF.GetStat().ToString()
                            Exit For
                        End If
                    End If
                Else
                    message = message + "The GetFormFieldType() method has failed with the status: " + gdpicturePDF.GetStat().ToString()
                    Exit For
                End If
            Else
                message = message + "The GetFormFieldId() method has failed with the status: " + gdpicturePDF.GetStat().ToString()
                Exit For
            End If
        Next
        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: GetFormFieldMaxLen";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
//Please use the PDF document created using the example from the SetFormFieldMaxLen() method.
if (gdpicturePDF.LoadFromFile("forms_textfield.pdf", false) == GdPictureStatus.OK)
{
    int count = gdpicturePDF.GetFormFieldsCount();
    if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
    {
        string message = "", value = "";
        if (count == 0)
            message = "This document does not contain any forms.";
        int formID = 0, maxLen = 0, j = 0;
        bool comb = false;
        PdfFormFieldType type = PdfFormFieldType.PdfFormFieldTypeUnknown;
        for (int i = 0; i < count; i++)
        {
            formID = gdpicturePDF.GetFormFieldId(i);
            if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
            {
                type = gdpicturePDF.GetFormFieldType(formID);
                if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                {
                    if (type == PdfFormFieldType.PdfFormFieldTypeText)
                    {
                        j++;
                        comb = gdpicturePDF.GetFormFieldComb(formID);
                        if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                        {
                            maxLen = gdpicturePDF.GetFormFieldMaxLen(formID);
                            if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                            {
                                value = gdpicturePDF.GetFormFieldValue(formID);
                                if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                                {
                                    if (comb)
                                    {
                                        if ((value.Length == maxLen) && (!value.Contains(" ")))
                                            message = message + "The " + j.ToString() + ".text field holds the CORRECT value = " + value + "\n";
                                        else
                                            message = message + "The " + j.ToString() + ".text field holds the INCORRECT value = " + value + "\n";
                                    }
                                    else
                                    {
                                        message = message + "The " + j.ToString() + ".text field has not set the Comb flag. Its value is " + value + ".\n";
                                    }
                                }
                                else
                                {
                                    message = message + "The GetFormFieldValue() method has failed with the status: " + gdpicturePDF.GetStat().ToString();
                                    break;
                                }
                            }
                            else
                            {
                                message = message + "The GetFormFieldMaxLen() method has failed with the status: " + gdpicturePDF.GetStat().ToString();
                                break;
                            }
                        }
                        else
                        {
                            message = message + "The GetFormFieldComb() method has failed with the status: " + gdpicturePDF.GetStat().ToString();
                            break;
                        }
                    }
                }
                else
                {
                    message = message + "The GetFormFieldType() method has failed with the status: " + gdpicturePDF.GetStat().ToString();
                    break;
                }
            }
            else
            {
                message = message + "The GetFormFieldId() method has failed with the status: " + gdpicturePDF.GetStat().ToString();
                break;
            }
        }
        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