PDFSignDll for .NET Framework 2.0 Code Example

C# Code Example


PDFSign PDFSign = new PDFSign("Enter your application license here");

//Load the PDF file
PDFSign.LoadPDFDocument(File.ReadAllBytes("c:\\source.pdf"));

//Load the certificate from .PFX
PDFSign.DigitalSignatureCertificate =
PDFSign.LoadCertificate(File.ReadAllBytes("c:\\cert.pfx"), "123456");

//Load the certificate from Microsoft Store
//PDFSign.DigitalSignatureCertificate =
PDFSign.LoadCertificate(false, "", "Digital certificates",
"Select the digital certificate", DigitalCertificateScope.ForDigitalSignature);

//Signing reason & location
PDFSign.SigningReason = "I approve this document";
PDFSign.SigningLocation = "Europe branch";

//Set the signature rectangle attributes
PDFSign.SignaturePage = 1;
PDFSign.SignatureBasicPosition = BasicSignatureLocation.TopRight;

//Custom signature position
//PDFSign.SignaturePosition = new System.Drawing.Rectangle(30, 30, 100, 150);

//insert an image on the signature
PDFSign.SignatureImage = File.ReadAllBytes("c:\\signature_image.jpg");
PDFSign.SignatureImagePosition = SignatureImageType.ImageAsBackground;

//Set the PDF signature properties
PDFSign.SigningReason = "Your signing reason";
PDFSign.SigningLocation = "Your signing location";

//signature text that will appear on the signature rectangle
PDFSign.SignatureText =
"Signed by:" + PDFSign.DigitalSignatureCertificate.GetNameInfo(
X509NameType.SimpleName, false) + "\n" +
"Date:" + DateTime.Now.ToString("yyyy.MM.dd HH:mm") + "\n" +
"Reason:"  + PDFSign.SigningReason;

//Time stamp the PDF file
PDFSign.TimeStamping.ServerURL = new Uri("http://ca.signfiles.com/TSAServer.aspx");

//digitally sign the PDF file
File.WriteAllBytes("c:\\dest.pdf", PDFSign.ApplyDigitalSignature());

Visual Basic.NET Code Example


Dim PDFSign As New PDFSign("Enter your application license here")

'Load the PDF file
PDFSign.LoadPDFDocument(System.IO.File.ReadAllBytes("c:\source.pdf"))

'Load the certificate from .PFX
PDFSign.DigitalSignatureCertificate =
PDFSign.LoadCertificate(System.IO.File.ReadAllBytes("c:\cert.pfx"), "123456")

'Load the certificate from Microsoft Store
'PDFSign.DigitalSignatureCertificate =
PDFSign.LoadCertificate(False, "", "Digital certificates",
"Select the digital certificate", DigitalCertificateScope.ForDigitalSignature)

'Signing reason & location
PDFSign.SigningReason = "I approve this document"
PDFSign.SigningLocation = "Europe branch"

'Set the signature rectangle attributes
PDFSign.SignaturePage = 1
PDFSign.SignatureBasicPosition = BasicSignatureLocation.TopRight

'Custom signature position
'PDFSign.SignaturePosition = New System.Drawing.Rectangle(30, 30, 100, 150)

'insert an image on the signature
PDFSign.SignatureImage = System.IO.File.ReadAllBytes("c:\signature_image.jpg")
PDFSign.SignatureImagePosition = SignatureImageType.ImageAsBackground

'Set the PDF signature properties
PDFSign.SigningReason = "Your signing reason"
PDFSign.SigningLocation = "Your signing location"

'signature text that will appear on the signature rectangle
PDFSign.SignatureText =
("Signed by:" & PDFSign.DigitalSignatureCertificate.GetNameInfo(
Security.Cryptography.X509Certificates.X509NameType.SimpleName, False) & vbLf &
"Date:" & DateTime.Now.ToString("yyyy.MM.dd HH:mm") & vbLf &
"Reason:") + PDFSign.SigningReason

'Time stamp the PDF file
PDFSign.TimeStamping.ServerURL = New Uri("http://ca.signfiles.com/TSAServer.aspx")

'digitally sign the PDF file
System.IO.File.WriteAllBytes("c:\dest.pdf", PDFSign.ApplyDigitalSignature())

Visual C++ Code Example


PDFSign ^ PDFSignObj = gcnew PDFSign("Enter your application license here");

//Load the PDF file
PDFSignObj->LoadPDFDocument(System::IO::File::ReadAllBytes("c:\\source.pdf"));

//Load the certificate from .PFX
PDFSignObj->DigitalSignatureCertificate =
PDFSignObj->LoadCertificate(System::IO::File::ReadAllBytes("c:\\cert.pfx"), "123456");

//Load the certificate from Microsoft Store
//PDFSignObj->DigitalSignatureCertificate =
PDFSignObj->LoadCertificate(false, "", "Digital certificates",
"Select the digital certificate", DigitalCertificateScope::ForDigitalSignature);

//Signing reason & location
PDFSignObj->SigningReason = "I approve this document";
PDFSignObj->SigningLocation = "Europe branch";

//Set the signature rectangle attributes
PDFSignObj->SignaturePage = 1;
PDFSignObj->SignatureBasicPosition = BasicSignatureLocation::TopRight;

//Custom signature position
//PDFSignObj->SignaturePosition = System::Drawing::Rectangle(30, 30, 100, 150);

//insert an image on the signature
PDFSignObj->SignatureImage = System::IO::File::ReadAllBytes("c:\\signature_image.jpg");
PDFSignObj->SignatureImagePosition = SignatureImageType::ImageAsBackground;

//Set the PDF signature properties
PDFSignObj->SigningReason = "Your signing reason";
PDFSignObj->SigningLocation = "Your signing location";

//signature text that will appear on the signature rectangle
PDFSignObj->SignatureText =
"Signed by:" + PDFSignObj->DigitalSignatureCertificate->GetNameInfo(
System::Security::Cryptography::X509Certificates::X509NameType::SimpleName, false)
+ "\n" + "Date:" +
DateTime::Now.ToString("yyyy.MM.dd HH:mm") + "\n" +
"Reason:" + PDFSignObj->SigningReason;

//Time stamp the PDF file
PDFSignObj->TimeStamping->ServerURL =
gcnew Uri("http://ca.signfiles.com/TSAServer.aspx");

//digitally sign the PDF file
System::IO::File::WriteAllBytes("c:\\dest.pdf", PDFSignObj->ApplyDigitalSignature());

Save a tree! Use digital signatures.