Skip to content
Guides

Create Digital Signatures

Creating a digital signature involves two steps:

  1. Create a Signature Field

  2. Sign within the Signature Field

By following these two steps, you can either self-sign a document or invite others to sign within the signature field you've created.

Create a Signature Field

ComPDFKit offers support for customizing the styles of the signature form field and allows you to customize the appearance of your signature using drawn, image, and typed signatures.

This example shows how to create a signature field:

C#
// Create a Signature Field. 
// 
// Page Index: 0
// Rect: CRect (28, 420, 150, 370)
// Border RGB: { 0, 0, 0 }  
// Widget Background RGB: { 150, 180, 210 }
// 
CPDFPage page = document.PageAtIndex(0);
            CPDFSignatureWidget signatureField = page.CreateWidget(C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS) as CPDFSignatureWidget;
            signatureField.SetRect(new CRect(28, 420, 150, 370)); 
            signatureField.SetWidgetBorderRGBColor(new byte[] { 0, 0, 0 });
            signatureField.SetWidgetBgRGBColor(new byte[] { 150, 180, 210 });
            signatureField.UpdateAp();

Sign Within the Signature Field

To sign within the signature field, you need to do three things:

  • Possess a certificate that conforms to the PKCS12 standard (in PFX or P12 format) and ensure that you know its password. You can create a compliant digital certificate using the built-in methods within the ComPDFKit SDK.

  • Set the appearance of the digital signature.

  • Write the data into the signature field.

This example shows how to sign within the signature field:

C#
// Sign in the signature field.
//
// Text: Grantor Name
// Content:
// Name: Get the grantor's name from the certificate
// Date: Now (yyyy.mm.dd)
// Reason: I am the owner of the document
// DN: Subject
// IsContentAlginLeft: False
// IsDrawLogo: True
// LogoBitmap: logo.png
// text color RGB: { 0, 0, 0 }
// Output file name: document.FileName + "_Signed.pdf"
//
string name = GetGrantorFromDictionary(certificate.SubjectDict) + "\n";
string date = DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss");
string reason = "I am the owner of the document.";
string location = certificate.SubjectDict["C"];
string DN = certificate.Subject;
CPDFSignatureConfig signatureConfig = new CPDFSignatureConfig
            {
                Text = GetGrantorFromDictionary(ce string filePath = outputPath + "\\" + document.FileName + "_Signed.pdf";
            signatureField.UpdataApWithSignature(signatureConfig);rtificate.SubjectDict),
                Content =
                "Name: " + name + "\n" +
                "Date: " + date + "\n" +
                "Reason: "+ reason +" \n" +
                "Location: "+ location + "\n" +
                "DN: " + DN + "\n",
                IsContentAlginLeft = false,
                IsDrawLogo = true,
                LogoBitmap = new Bitmap("Logo.png"),
                textColor = new float[] { 0, 0, 0 },
                contentColor = new float[] { 0, 0, 0 }
            };
string filePath = outputPath + "\\" + document.FileName + "_Signed.pdf";
            signatureField.UpdataApWithSignature(signatureConfig);
document.WriteSignatureToFilePath(signatureField,
                filePath ,
                certificatePath, password,
                location,
                reason, CPDFSignaturePermissions.CPDFSignaturePermissionsNone);