Dim caption As String = "Example: SetFormFieldOptional"
Dim gdpicturePDF As New GdPicturePDF()
If (gdpicturePDF.NewPDF() = GdPictureStatus.OK) AndAlso
(gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) = GdPictureStatus.OK) Then
Dim fontName As String = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontTimesBold)
If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
Dim fieldID As Integer = gdpicturePDF.AddTextFormField(50, 700, 200, 30, "Name", "GdPicture", False, fontName, 12, 165, 42, 42)
If (gdpicturePDF.GetStat() = GdPictureStatus.OK) AndAlso
(gdpicturePDF.SetFormFieldBorderColor(fieldID, 0, 0, 255) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.SetFormFieldBackgroundColor(fieldID, 255, 228, 196) = GdPictureStatus.OK) Then
Dim ocgID As Integer = gdpicturePDF.NewOCG("Form field layer")
If (gdpicturePDF.GetStat() = GdPictureStatus.OK) AndAlso
(gdpicturePDF.SetFormFieldOptional(fieldID, ocgID) = GdPictureStatus.OK) Then
If (gdpicturePDF.SetOCGExportState(ocgID, PdfOcgState.StateOff) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.SetOCGLockedState(ocgID, True) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.SetOCGPrintState(ocgID, PdfOcgState.StateOn) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.SetOCGViewState(ocgID, PdfOcgState.StateOn) = GdPictureStatus.OK) Then
If gdpicturePDF.SaveToFile("test_FormFieldLayer.pdf") = GdPictureStatus.OK Then
MessageBox.Show("The example HAS been followed successfully and the file has been saved.", caption)
Else
MessageBox.Show("The example HAS been followed successfully, but the file can't be saved. Status: " + gdpicturePDF.GetStat().ToString(), caption)
End If
Else
MessageBox.Show("Setting up layer's options has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
End If
Else
MessageBox.Show("The NewOCG() or SetFormFieldOptional() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
End If
Else
MessageBox.Show("Adding the form field has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
End If
Else
MessageBox.Show("The AddStandardFont() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
End If
Else
MessageBox.Show("The document can't be created.", caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: SetFormFieldOptional";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
if ((gdpicturePDF.NewPDF() == GdPictureStatus.OK) &&
(gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) == GdPictureStatus.OK))
{
string fontName = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontTimesBold);
if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
{
int fieldID = gdpicturePDF.AddTextFormField(50, 700, 200, 30, "Name", "GdPicture", false, fontName, 12, 165, 42, 42);
if ((gdpicturePDF.GetStat() == GdPictureStatus.OK) &&
(gdpicturePDF.SetFormFieldBorderColor(fieldID, 0, 0, 255) == GdPictureStatus.OK) &&
(gdpicturePDF.SetFormFieldBackgroundColor(fieldID, 255, 228, 196) == GdPictureStatus.OK))
{
int ocgID = gdpicturePDF.NewOCG("Form field layer");
if ((gdpicturePDF.GetStat() == GdPictureStatus.OK) &&
(gdpicturePDF.SetFormFieldOptional(fieldID, ocgID) == GdPictureStatus.OK))
{
if ((gdpicturePDF.SetOCGExportState(ocgID, PdfOcgState.StateOff) == GdPictureStatus.OK) &&
(gdpicturePDF.SetOCGLockedState(ocgID, true) == GdPictureStatus.OK) &&
(gdpicturePDF.SetOCGPrintState(ocgID, PdfOcgState.StateOn) == GdPictureStatus.OK) &&
(gdpicturePDF.SetOCGViewState(ocgID, PdfOcgState.StateOn) == GdPictureStatus.OK))
{
if (gdpicturePDF.SaveToFile("test_FormFieldLayer.pdf") == GdPictureStatus.OK)
MessageBox.Show("The example HAS been followed successfully and the file has been saved.", caption);
else
MessageBox.Show("The example HAS been followed successfully, but the file can't be saved. Status: " + gdpicturePDF.GetStat().ToString(), caption);
}
else
{
MessageBox.Show("Setting up layer's options has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
}
}
else
{
MessageBox.Show("The NewOCG() or SetFormFieldOptional() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
}
}
else
{
MessageBox.Show("Adding the form field has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
}
}
else
{
MessageBox.Show("The AddStandardFont() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
}
}
else
{
MessageBox.Show("The document can't be created.", caption);
}
gdpicturePDF.Dispose();