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
|
|
|