Dim caption As String = "SetSignaturePosFromPlaceHolder"
Dim gdpicturePDF As GdPicturePDF = New GdPicturePDF()
'Please take a PDF document created in the example for the AddSignatureFormField() method.
Dim status As GdPictureStatus = gdpicturePDF.LoadFromFile("test_AddSignatureFormField.pdf", False)
If status <> GdPictureStatus.OK Then
MessageBox.Show("The file can't be loaded.", caption)
Goto [Error]
End If
'Please set the corresponding certificate - this is a mandatory step.
'Set the signature information. At least one parameter must be defined for the successful signing.
status = gdpicturePDF.SetSignatureInfo("Orpalis", "GdPicturePDF", "Toulouse (France)", "")
If status <> GdPictureStatus.OK Then
MessageBox.Show("The method SetSignatureInfo() has failed with the status " + status.ToString(), caption)
Goto [Error]
End If
'Find a placeholder for a signature.
Dim formID As Integer = 0
Dim formType As PdfFormFieldType = PdfFormFieldType.PdfFormFieldTypeUnknown
Dim signatureName As String = ""
'Here we demonstrate how to find out the signature's name (the name of the signature form field (placeholder)).
Dim formsCount As Integer = gdpicturePDF.GetFormFieldsCount()
status = gdpicturePDF.GetStat()
If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
If formsCount = 0 Then
MessageBox.Show("This document does not include form fields.", caption)
Goto [Error]
End If
'This step is strongly bound to the file "test_AddSignatureFormField.pdf".
For i As Integer = 0 To formsCount - 1 - 1
formID = gdpicturePDF.GetFormFieldId(i)
status = gdpicturePDF.GetStat()
If status = GdPictureStatus.OK Then
formType = gdpicturePDF.GetFormFieldType(formID)
status = gdpicturePDF.GetStat()
If (status = GdPictureStatus.OK) AndAlso (formType = PdfFormFieldType.PdfFormFieldTypeSignature) Then
signatureName = gdpicturePDF.GetFormFieldTitle(formID)
status = gdpicturePDF.GetStat()
'Only one signature form field is expected here - see the "test_AddSignatureFormField.pdf" file.
Exit For
End If
End If
Next
If status <> GdPictureStatus.OK Then
MessageBox.Show("Can't find a signature placeholder field. Status: " + status.ToString(), caption)
Goto [Error]
End If
Else
MessageBox.Show("The method GetFormFieldsCount() has failed with the status " + status.ToString(), caption)
Goto [Error]
End If
'Set the signature's location on the current page. This step is optional.
'If this step is omitted, the signature will be invisible.
status = gdpicturePDF.SetSignaturePosFromPlaceHolder(signatureName)
'If you know the form field's name, you can use it directly like this (see the file "test_AddSignatureFormField.pdf"):
'status = gdpicturePDF.SetSignaturePosFromPlaceHolder("Signature1")
If status <> GdPictureStatus.OK Then
MessageBox.Show("The method SetSignaturePosFromPlaceHolder() has failed with the status: " + status.ToString(), caption)
Goto [Error]
End If
'Please see the complete sample in the ApplySignature() method for next steps to follow.
[error]:
gdpicturePDF.Dispose()
string caption = "SetSignaturePosFromPlaceHolder";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
//Please take a PDF document created in the example for the AddSignatureFormField() method.
GdPictureStatus status = gdpicturePDF.LoadFromFile("test_AddSignatureFormField.pdf", false);
if (status != GdPictureStatus.OK)
{
MessageBox.Show("The file can't be loaded.", caption);
goto error;
}
//Please set the corresponding certificate - this is a mandatory step.
//Set the signature information. At least one parameter must be defined for the successful signing.
status = gdpicturePDF.SetSignatureInfo("Orpalis", "GdPicturePDF", "Toulouse (France)", "");
if (status != GdPictureStatus.OK)
{
MessageBox.Show("The method SetSignatureInfo() has failed with the status " + status.ToString(), caption);
goto error;
}
//Find a placeholder for a signature.
int formID = 0;
PdfFormFieldType formType = PdfFormFieldType.PdfFormFieldTypeUnknown;
string signatureName = "";
//Here we demonstrate how to find out the signature's name (the name of the signature form field (placeholder)).
int formsCount = gdpicturePDF.GetFormFieldsCount();
status = gdpicturePDF.GetStat();
if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
{
if (formsCount == 0)
{
MessageBox.Show("This document does not include form fields.", caption);
goto error;
}
//This step is strongly bound to the file "test_AddSignatureFormField.pdf".
for (int i = 0; i < formsCount-1; i++ )
{
formID = gdpicturePDF.GetFormFieldId(i);
status = gdpicturePDF.GetStat();
if (status == GdPictureStatus.OK)
{
formType = gdpicturePDF.GetFormFieldType(formID);
status = gdpicturePDF.GetStat();
if ((status == GdPictureStatus.OK) &&
(formType == PdfFormFieldType.PdfFormFieldTypeSignature))
{
signatureName = gdpicturePDF.GetFormFieldTitle(formID);
status = gdpicturePDF.GetStat();
//Only one signature form field is expected here - see the "test_AddSignatureFormField.pdf" file.
break;
}
}
}
if (status != GdPictureStatus.OK)
{
MessageBox.Show("Can't find a signature placeholder field. Status: " + status.ToString(), caption);
goto error;
}
}
else
{
MessageBox.Show("The method GetFormFieldsCount() has failed with the status " + status.ToString(), caption);
goto error;
}
//Set the signature's location on the current page. This step is optional.
//If this step is omitted, the signature will be invisible.
status = gdpicturePDF.SetSignaturePosFromPlaceHolder(signatureName);
//If you know the form field's name, you can use it directly like this (see the file "test_AddSignatureFormField.pdf"):
//status = gdpicturePDF.SetSignaturePosFromPlaceHolder("Signature1");
if (status != GdPictureStatus.OK)
{
MessageBox.Show("The method SetSignaturePosFromPlaceHolder() has failed with the status: " + status.ToString(), caption);
goto error;
}
//Please see the complete sample in the ApplySignature() method for next steps to follow.
error:
gdpicturePDF.Dispose();