Sign the digital signature using a private key and password.

 

   

Syntax
 

XSignature.Sign PathOrData, Password

 

   

Params
 
Name Type Description
PathOrData String or Array of Bytes The file path to or the data for the PFX/PKCS #12 (.pfx or .p12) file used for signing.
Password String The password used to authorize use of the private key.

 

   

Notes
 

Use this method to sign a signature field.

In order to sign a signature, you need to use your private key. To authorize the use of this key, you need to provide your password.

Typically, this password-protected private key is held in an PFX/PKCS #12 (.pfx or .p12) file. So to perform the signing operation, you provide a path to this file and a password to allow use of the private key.

Time-stamped signatures can be produced by using the service of a Time Stamping Authority (TSA). See TimestampServiceUrl.

If you are signing multiple signature fields in the same PDF document, you should call Commit manually after each signing operation bar the last operation.

If the file is not available, if the file is invalid or if the password is incorrect, then this method will raise an error.

 

   

Example
 

Read a document and sign a signature field embedded within that document. Before signing, we specify a location and a reason why the document is being digitally signed.

Set theDoc = Server.CreateObject("ABCpdf12.Doc")
theDoc.Read Server.MapPath("../Rez/Authorization.pdf")
Set theSig = theDoc.Form("Signature")
theSig.Location = "Washington"
theSig.Reason = "Schedule Agreed"
theSig.Sign Server.MapPath("../Rez/JohnSmith.pfx"), "1234"
theDoc.Save Server.MapPath("Signed.pdf")

The following AddSignature method simplified from InteractiveForm.AddSignature in the Annotations example project adds and signs a signature.

Set theSig = AddSignature(theDoc, "40 100 240 150", "Signature1", _
  Server.MapPath("JohnSmith.pfx"), "1234", "I am the author", "New York")

Function AddSignature(doc, fieldRect, fieldName, keyPath, keyPassword, reason, location)
  ' make sure that doc.Page is not zero, i.e. the current page exists, before continuing

  Dim eid
  eid = doc.GetInfo(doc.Root, "/AcroForm:Ref")
  If Len(eid) <= 0 Then eid = 0
  If eid = 0 Then
    Dim acro
    acro = doc.GetInfo(doc.Root, "/AcroForm")
    If acro = "" Then acro = "<</Fields []>>"
    eid = doc.AddObject(acro)
    doc.SetInfo doc.Root, "/AcroForm:Ref", eid
  End If
  Dim font
  font = doc.AddFont("Times-Roman")
  doc.SetInfo eid, "/DR/Font/TimesRoman:Ref", font

  Dim fieldId
  fieldId = doc.AddObject("<</Type /Annot /Subtype /Widget /F 4 /FT /Sig /DA (/TimesRoman 0 Tf 0 g)>>")
  Dim sigDictId
  sigDictId = doc.AddObject("<</Filter /Adobe.PPKLite /SubFilter /adbe.pkcs7.detached>>")
  doc.SetInfo fieldId, "/V:Ref", sigDictId

  doc.SetInfo fieldId, "/T:Text", fieldName
  doc.SetInfo doc.Page, "/Annots*[]:Ref", fieldId
  doc.SetInfo fieldId, "/P:Ref", doc.Page
  doc.SetInfo eid, "/Fields*[]:Ref", fieldId
  doc.SetInfo fieldId, "/Rect:Rect", fieldRect

  Dim sig
  Set sig = doc.Form(fieldName)
  sig.Sign keyPath, keyPassword
  If Len(reason) > 0 Then doc.SetInfo sigDictId, "/Reason:Text", reason
  If Len(location) > 0 Then doc.SetInfo sigDictId, "/Location:Text", location
  If Len(sig.Signer) > 0 Then doc.SetInfo sigDictId, "/Name:Text", sig.Signer

  doc.SetInfo eid, "/SigFlags:Num", "3"
  Set AddSignature = sig
End Function