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:

javascript
docViewer.addAnnotations({
  type: 'signatureFields',
  rect: {
    left: 102,
    top: 136,
    right: 161,
    bottom: 156
  },
  pageIndex: 0
});

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:

javascript
const { subject } = await docViewer.loadCertificates({
  pkcs12Buffer: pkcs12.buffer,
  password: password
})

const content = "Name: " + subject.CN + "\n" +
  "Date: " + date + "\n" +
  "Reason: "+ 'I am the owner of the document.' +" \n" +
  "Location: "+ location + "\n"

docViewer.handleSign({
    type: 1,
    flag: 'save',
    param: {
      annotation,
      content,
      text: 'Text'
      isContentAlginLeft: false
    },
    pkcs12Buffer: pkcs12.buffer,
    password: password
  })