SetFormFieldsNeedAppearances Method (GdPicturePDF)
Sets the value of NeedAppearances flag related to interactive form fields 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.
public function SetFormFieldsNeedAppearances(
: Boolean
): GdPictureStatus;
public function SetFormFieldsNeedAppearances(
: boolean
) : GdPictureStatus;
'Declaration
Public Function SetFormFieldsNeedAppearances( _
ByVal As Boolean _
) As GdPictureStatus
Parameters
- NeedAppearances
- Set this parameter to true, if you want to enable the NeedAppearances flag, otherwise set it to false to disable it.
Setting this flag to true can improve rendering of incorrectly constructed form fields appearances for proper document viewing.
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.
How to force form fields appearance reconstruction during the rendering process.
Dim caption As String = "Example: SetFormFieldsNeedAppearances"
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: SetFormFieldsNeedAppearances";
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();