Dim caption As String = "Digital Signature"
Dim gdpicturePDF As New GdPicturePDF()
Dim status As GdPictureStatus = gdpicturePDF.LoadFromFile("file_to_sign.pdf", False)
If status <> GdPictureStatus.OK Then
MessageBox.Show("The file can't be loaded.", caption)
Goto [Error]
End If
'Mandatory steps are step #1 and step #2 and the last step #5.
'Step 1 : Set the certificate, your digital ID file.
status = gdpicturePDF.SetSignatureCertificateFromP12("your_digital_ID.pfx", "your_password")
If status <> GdPictureStatus.OK Then
MessageBox.Show("The method SetSignatureCertificateFromP12() has failed with the status: " + status.ToString(), caption)
Goto [Error]
End If
'Step 2 : Set the signature information. At least one parameter must be set, others may stay empty.
status = gdpicturePDF.SetSignatureInfo("Orpalis", "Important PDF", "Toulouse (France)", "[email protected]")
If status <> GdPictureStatus.OK Then
MessageBox.Show("The method SetSignatureInfo() has failed with the status: " + status.ToString(), caption)
Goto [Error]
End If
'Optional steps.
'Step 3a : Set the signature's location on the current page. If this step is omitted, the signature will be invisible.
status = gdpicturePDF.SetSignaturePos(300, 100, 200, 100)
If status <> GdPictureStatus.OK Then
MessageBox.Show("The method SetSignaturePos() has failed with the status: " + status.ToString(), caption)
Goto [Error]
End If
'Step 3b : Set the text to be displayed within the signature's bounding box. The text will not be drawn if the signature is invisible.
status = gdpicturePDF.SetSignatureText("", "", 12, Color.Navy, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, True)
If status <> GdPictureStatus.OK Then
MessageBox.Show("The method SetSignatureText() has failed with the status: " + status.ToString(), caption)
Goto [Error]
End If
'Step 3c : Set the image to be displayed within the signature's bounding box. The image will not be drawn if the signature is invisible.
Dim imageName As String = gdpicturePDF.AddJpegImageFromFile("your_image.jpg")
status = gdpicturePDF.GetStat()
If status <> GdPictureStatus.OK Then
MessageBox.Show("The method AddJpegImageFromFile() has failed with the status: " + status.ToString(), caption)
Goto [Error]
End If
status = gdpicturePDF.SetSignatureStampImage(imageName)
If status <> GdPictureStatus.OK Then
MessageBox.Show("The method SetSignatureStampImage() has failed with the status: " + status.ToString(), caption)
Goto [Error]
End If
'Step 3d : Set the icon that represents the validity of the signature.
status = gdpicturePDF.SetSignatureValidationMark(True)
If status <> GdPictureStatus.OK Then
MessageBox.Show("The method SetSignatureValidationMark() has failed with the status: " + status.ToString(), caption)
Goto [Error]
End If
'Step 4a : Set the signature certification level.
status = gdpicturePDF.SetSignatureCertificationLevel(PdfSignatureCertificationLevel.NotCertified)
If status <> GdPictureStatus.OK Then
MessageBox.Show("The method SetSignatureCertificationLevel() has failed with the status: " + status.ToString(), caption)
Goto [Error]
End If
'Step 4b : Set the hash algorithm.
status = gdpicturePDF.SetSignatureHash(PdfSignatureHash.SHA256)
If status <> GdPictureStatus.OK Then
MessageBox.Show("The method SetSignatureHash() has failed with the status " + status.ToString(), caption)
Goto [Error]
End If
'Step 4c : Set the timestamp information.
status = gdpicturePDF.SetSignatureTimestampInfo("your_time_stamp_server_url", "your_username", "your_password")
If status <> GdPictureStatus.OK Then
MessageBox.Show("The method SetSignatureTimestampInfo() has failed with the status " + status.ToString(), caption)
GoTo [error]
End If
'Step 5 : The last step - sign. This step must be the last one. All other optional steps may be done in any order.
status = gdpicturePDF.ApplySignature("signed.pdf", PdfSignatureMode.PdfSignatureModeAdobePPKMS, True)
If status = GdPictureStatus.OK Then
MessageBox.Show("The document has been signed successfully and the file has been saved.", caption)
Else
MessageBox.Show("The method ApplySignature() has failed with the status: " + status.ToString(), caption)
End If
[error]:
gdpicturePDF.Dispose()
string caption = "Digital Signature";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
GdPictureStatus status = gdpicturePDF.LoadFromFile("file_to_sign.pdf", false);
if (status != GdPictureStatus.OK)
{
MessageBox.Show("The file can't be loaded.", caption);
goto error;
}
//Mandatory steps are step #1 and step #2 and the last step #5.
//Step 1 : Set the certificate, your digital ID file.
status = gdpicturePDF.SetSignatureCertificateFromP12("your_digital_ID.pfx", "your_password");
if (status != GdPictureStatus.OK)
{
MessageBox.Show("The method SetSignatureCertificateFromP12() has failed with the status: " + status.ToString(), caption);
goto error;
}
//Step 2 : Set the signature information. At least one parameter must be set, others may stay empty.
status = gdpicturePDF.SetSignatureInfo("Orpalis", "Important PDF", "Toulouse (France)", "[email protected]");
if (status != GdPictureStatus.OK)
{
MessageBox.Show("The method SetSignatureInfo() has failed with the status: " + status.ToString(), caption);
goto error;
}
//Optional steps.
//Step 3a : Set the signature's location on the current page. If this step is omitted, the signature will be invisible.
status = gdpicturePDF.SetSignaturePos(300, 100, 200, 100);
if (status != GdPictureStatus.OK)
{
MessageBox.Show("The method SetSignaturePos() has failed with the status: " + status.ToString(), caption);
goto error;
}
//Step 3b : Set the text to be displayed within the signature's bounding box. The text will not be drawn if the signature is invisible.
status = gdpicturePDF.SetSignatureText("", "", 12, Color.Navy, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, true);
if (status != GdPictureStatus.OK)
{
MessageBox.Show("The method SetSignatureText() has failed with the status: " + status.ToString(), caption);
goto error;
}
//Step 3c : Set the image to be displayed within the signature's bounding box. The image will not be drawn if the signature is invisible.
string imageName = gdpicturePDF.AddJpegImageFromFile("your_image.jpg");
status = gdpicturePDF.GetStat();
if (status != GdPictureStatus.OK)
{
MessageBox.Show("The method AddJpegImageFromFile() has failed with the status: " + status.ToString(), caption);
goto error;
}
status = gdpicturePDF.SetSignatureStampImage(imageName);
if (status != GdPictureStatus.OK)
{
MessageBox.Show("The method SetSignatureStampImage() has failed with the status: " + status.ToString(), caption);
goto error;
}
//Step 3d : Set the icon that represents the validity of the signature.
status = gdpicturePDF.SetSignatureValidationMark(true);
if (status != GdPictureStatus.OK)
{
MessageBox.Show("The method SetSignatureValidationMark() has failed with the status: " + status.ToString(), caption);
goto error;
}
//Step 4a : Set the signature certification level.
status = gdpicturePDF.SetSignatureCertificationLevel(PdfSignatureCertificationLevel.NotCertified);
if (status != GdPictureStatus.OK)
{
MessageBox.Show("The method SetSignatureCertificationLevel() has failed with the status: " + status.ToString(), caption);
goto error;
}
//Step 4b : Set the hash algorithm.
status = gdpicturePDF.SetSignatureHash(PdfSignatureHash.SHA256);
if (status != GdPictureStatus.OK)
{
MessageBox.Show("The method SetSignatureHash() has failed with the status " + status.ToString(), caption);
goto error;
}
//Step 4c : Set the timestamp information.
status = gdpicturePDF.SetSignatureTimestampInfo("your_time_stamp_server_url", "your_username", "your_password");
if (status != GdPictureStatus.OK)
{
MessageBox.Show("The method SetSignatureTimestampInfo() has failed with the status " + status.ToString(), caption);
goto error;
}
//Step 5 : The last step - sign. This step must be the last one. All other optional steps may be done in any order.
status = gdpicturePDF.ApplySignature("signed.pdf", PdfSignatureMode.PdfSignatureModeAdobePPKMS, true);
if (status == GdPictureStatus.OK)
MessageBox.Show("The document has been signed successfully and the file has been saved.", caption);
else
MessageBox.Show("The method ApplySignature() has failed with the status: " + status.ToString(), caption);
error:
gdpicturePDF.Dispose();