Example





In This Topic
GdPicture14 Namespace / GdPicturePDF Class / GetFormFieldsNeedAppearances Method

GetFormFieldsNeedAppearances Method (GdPicturePDF)

In This Topic
Returns the value of NeedAppearances flag related to interactive form fields, if any are present in the currently loaded PDF document.

Sometimes fields may contain values that are not know until the document is viewed. This flag specifies whether to construct appearance streams and appearance dictionaries for form fields in the loaded document to properly render the document when viewing.

Syntax
'Declaration
 
Public Function GetFormFieldsNeedAppearances() As Boolean
public bool GetFormFieldsNeedAppearances()
public function GetFormFieldsNeedAppearances(): Boolean; 
public function GetFormFieldsNeedAppearances() : boolean;
public: bool GetFormFieldsNeedAppearances(); 
public:
bool GetFormFieldsNeedAppearances(); 

Return Value

true if the NeedAppearances flag is set in the form fields dictionary, otherwise false. 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 inform you, that this flag is only related to interactive form fields, if any are present in the currently loaded PDF document. Please use the SetFormFieldsNeedAppearances method to force the renderer to construct form fields appearances before viewing.

Example
How to force form fields appearance reconstruction during the rendering process.
Dim caption As String = "Example: GetFormFieldsNeedAppearances"
Dim gdpicturePDF As GdPicturePDF = New GdPicturePDF()
Dim gdpictureImaging As GdPictureImaging = New GdPictureImaging()
If gdpicturePDF.LoadFromFile("test.pdf", False) = GdPictureStatus.OK Then
    Dim formsCount As Integer = gdpicturePDF.GetFormFieldsCount()
    If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
        If formsCount > 0 Then
            If (gdpicturePDF.GetFormFieldsNeedAppearances() = False) AndAlso
               (gdpicturePDF.GetStat() = GdPictureStatus.OK) Then
                'Forcing the toolkit to construct form fields appearances for proper rendering.
                gdpicturePDF.SetFormFieldsNeedAppearances(True)
            End If
        End If
        If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
            Dim count As Integer = gdpicturePDF.GetPageCount()
            If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                Dim message As String = ""
                Dim image_index As Integer = 0
                Dim filename As String = "image_page0.png"
                For i As Integer = 1 To count
                    If gdpicturePDF.SelectPage(i) = GdPictureStatus.OK Then
                        image_index = gdpicturePDF.RenderPageToGdPictureImage(200, True)
                        If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                            filename = filename.Replace((i - 1).ToString(), i.ToString())
                            If gdpictureImaging.SaveAsPNG(image_index, filename) = GdPictureStatus.OK Then
                                message = message + "The image of the page nr." + i.ToString() + " has been successfully saved." + vbCrLf
                            Else
                                message = message + "The SaveAsPNG() method has failed for the page nr." + i.ToString() + " with the status: " + gdpicturePDF.GetStat().ToString() + vbCrLf
                            End If
            
                            gdpictureImaging.ReleaseGdPictureImage(image_index)
                        Else
                            message = message + "The RenderPageToGdPictureImage() method has failed for the page nr." + i.ToString() + " with the status: " + gdpicturePDF.GetStat().ToString() + vbCrLf
                        End If
                    Else
                        message = message + "The SelectPage() method has failed for the page nr." + i.ToString() + " with the status: " + gdpicturePDF.GetStat().ToString() + vbCrLf
                    End If
                Next
                MessageBox.Show(message, caption)
            Else
                MessageBox.Show("The GetPageCount() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
            End If
        Else
            MessageBox.Show("The handling of form fields appearance flag has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
        End If
    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
gdpictureImaging.Dispose()
gdpicturePDF.Dispose()
string caption = "Example: GetFormFieldsNeedAppearances";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
GdPictureImaging gdpictureImaging = new GdPictureImaging();
if (gdpicturePDF.LoadFromFile("test.pdf", false) == GdPictureStatus.OK)
{
    int formsCount = gdpicturePDF.GetFormFieldsCount();
    if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
    {
        if (formsCount > 0)
        {
            if ((gdpicturePDF.GetFormFieldsNeedAppearances() == false) &&
                (gdpicturePDF.GetStat() == GdPictureStatus.OK))
                //Forcing the toolkit to construct form fields appearances for proper rendering.
                gdpicturePDF.SetFormFieldsNeedAppearances(true);
        }
        if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
        {
            int count = gdpicturePDF.GetPageCount();
            if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
            {
                string message = "";
                int image_index = 0;
                string filename = "image_page0.png";
                for (int i = 1; i <= count; i++)
                {
                    if (gdpicturePDF.SelectPage(i) == GdPictureStatus.OK)
                    {
                        image_index = gdpicturePDF.RenderPageToGdPictureImage(200, true);
                        if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                        {
                            filename = filename.Replace((i - 1).ToString(), i.ToString());
                            if (gdpictureImaging.SaveAsPNG(image_index, filename) == GdPictureStatus.OK)
                                message = message + "The image of the page nr." + i.ToString() + " has been successfully saved.\n";
                            else
                                message = message + "The SaveAsPNG() method has failed for the page nr." + i.ToString() + " with the status: " + gdpicturePDF.GetStat().ToString() + "\n";
                            gdpictureImaging.ReleaseGdPictureImage(image_index);
                            //Or you can use this one:
                            //GdPictureDocumentUtilities.DisposeImage(image_index)
                        }
                        else
                            message = message + "The RenderPageToGdPictureImage() method has failed for the page nr." + i.ToString() + " with the status: " + gdpicturePDF.GetStat().ToString() + "\n";
                    }
                    else
                        message = message + "The SelectPage() method has failed for the page nr." + i.ToString() + " with the status: " + gdpicturePDF.GetStat().ToString() + "\n";
                }
                MessageBox.Show(message, caption);
            }
            else
                MessageBox.Show("The GetPageCount() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
        }
        else
            MessageBox.Show("The handling of form fields appearance flag has failed with the status: " + gdpicturePDF.GetStat().ToString(), 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);
gdpictureImaging.Dispose();
gdpicturePDF.Dispose();
See Also