GdPicture.NET.14.API
GdPicture14 Namespace / GdPicturePDF Class / GetFormFieldTextAlignment 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
GetFormFieldTextAlignment Method (GdPicturePDF)
In This Topic
Returns the justification, in other words the mode of the text alignment used when displaying text in a required form field, that is specified by its unique form field's identifier and it is related to the currently loaded PDF document.
Syntax
'Declaration
 
Public Function GetFormFieldTextAlignment( _
   ByVal FieldId As Integer _
) As TextAlignment
public TextAlignment GetFormFieldTextAlignment( 
   int FieldId
)
public function GetFormFieldTextAlignment( 
    FieldId: Integer
): TextAlignment; 
public function GetFormFieldTextAlignment( 
   FieldId : int
) : TextAlignment;
public: TextAlignment GetFormFieldTextAlignment( 
   int FieldId
) 
public:
TextAlignment GetFormFieldTextAlignment( 
   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

A member of the TextAlignment enumeration. 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 inform you that this property is only related to the form fields, which contains variable text, like text fields or scrollable list boxes.

Example
How to change the centered text alignment to near one for all multiline text form fields in the current document.
Dim caption As String = "Example: GetFormFieldTextAlignment"
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."
        Dim formID As Integer = 0
        Dim multiline As Boolean = False, save As Boolean = False
        Dim type As PdfFormFieldType = PdfFormFieldType.PdfFormFieldTypeUnknown
        Dim textalign As TextAlignment = TextAlignment.TextAlignmentCenter
        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
                        multiline = gdpicturePDF.GetFormFieldMultiLine(formID)
                        If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                            textalign = gdpicturePDF.GetFormFieldTextAlignment(formID)
                            If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                                If textalign = TextAlignment.TextAlignmentCenter Then
                                    If gdpicturePDF.SetFormFieldTextAlignment(formID, TextAlignment.TextAlignmentNear) = GdPictureStatus.OK Then
                                        save = True
                                    Else
                                        message = message + "The SetFormFieldTextAlignment() method has failed with the status: " + gdpicturePDF.GetStat().ToString() + vbCrLf
                                    End If
                                End If
                            Else
                                message = message + "The GetFormFieldTextAlignment() method has failed with the status: " + gdpicturePDF.GetStat().ToString() + vbCrLf
                            End If
                        Else
                            message = message + "The GetFormFieldMultiLine() method has failed with the status: " + gdpicturePDF.GetStat().ToString() + vbCrLf
                        End If
                    End If
                Else
                    message = message + "The GetFormFieldType() method has failed with the status: " + gdpicturePDF.GetStat().ToString() + vbCrLf
                End If
            Else
                message = message + "The GetFormFieldId() method has failed with the status: " + gdpicturePDF.GetStat().ToString() + vbCrLf
                Exit For
            End If
        Next
        If save Then
            If gdpicturePDF.SaveToFile("forms_updated.pdf") = GdPictureStatus.OK Then
                message = message + "The example has been followed successfully and the file has been saved."
            Else
                message = message + "The example has been followed successfully, but the file can't be saved. Status: " + gdpicturePDF.GetStat().ToString()
            End If
        Else
            message = message + "The document has not been changed, so it has not been saved as well."
        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: GetFormFieldTextAlignment";
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.";
        int formID = 0;
        bool multiline = false, save = false;
        PdfFormFieldType type = PdfFormFieldType.PdfFormFieldTypeUnknown;
        TextAlignment textalign = TextAlignment.TextAlignmentCenter;
        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)
                    {
                        multiline = gdpicturePDF.GetFormFieldMultiLine(formID);
                        if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                        {
                            textalign = gdpicturePDF.GetFormFieldTextAlignment(formID);
                            if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                            {
                                if (textalign == TextAlignment.TextAlignmentCenter)
                                    if (gdpicturePDF.SetFormFieldTextAlignment(formID, TextAlignment.TextAlignmentNear) == GdPictureStatus.OK)
                                        save = true;
                                    else
                                        message = message + "The SetFormFieldTextAlignment() method has failed with the status: " + gdpicturePDF.GetStat().ToString() + "\n";
                            }
                            else
                                message = message + "The GetFormFieldTextAlignment() method has failed with the status: " + gdpicturePDF.GetStat().ToString() + "\n";
                        }
                        else
                            message = message + "The GetFormFieldMultiLine() method has failed with the status: " + gdpicturePDF.GetStat().ToString() + "\n";
                    }
                }
                else
                    message = message + "The GetFormFieldType() method has failed with the status: " + gdpicturePDF.GetStat().ToString() + "\n";
            }
            else
            {
                message = message + "The GetFormFieldId() method has failed with the status: " + gdpicturePDF.GetStat().ToString() + "\n";
                break;
            }
        }
        if (save)
        {
            if (gdpicturePDF.SaveToFile("forms_updated.pdf") == GdPictureStatus.OK)
                message = message + "The example has been followed successfully and the file has been saved.";
            else
                message = message + "The example has been followed successfully, but the file can't be saved. Status: " + gdpicturePDF.GetStat().ToString();
        }
        else
            message = message + "The document has not been changed, so it has not been saved as well.";
        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