Public Sub Save_Sheet_As_PDF_Add_2_Signature_Fields()
Dim PDDoc As Object
Dim AVDoc As Object
Dim JSO As Object
Dim formField As Object
Dim inputPDFfile As String, outputPDFfile As String
Dim coords() As Variant
Const TOP_LEFT_X = 50
Const TOP_LEFT_Y = 60
Const WIDTH = 200
Const HEIGHT = 30
With ActiveSheet
.Range("F1").Value = "Created " & Now
inputPDFfile = ThisWorkbook.Path & "\" & .Name & ".pdf"
outputPDFfile = ThisWorkbook.Path & "\" & .Name & " WITH 2 SIGNATURE FIELDS.pdf"
.ExportAsFixedFormat Type:=xlTypePDF, Filename:=inputPDFfile, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End With
Set PDDoc = CreateObject("AcroExch.PDDoc")
Set AVDoc = CreateObject("AcroExch.AVDoc")
If PDDoc.Open(inputPDFfile) Then
Set JSO = PDDoc.GetJSObject
'The 4th argument to JSO.addField is an array of coordinates specifying the position and size of the signature field's bounding rectangle,
'with origin (0,0) at bottom left of page, in the following order: top-left x, top-left y, bottom-right x and bottom-right y.
'1st signature field
coords = Array(TOP_LEFT_X, TOP_LEFT_Y, TOP_LEFT_X + WIDTH, TOP_LEFT_Y - HEIGHT)
Set formField = JSO.addField("SignatureField1", "signature", 0, coords) '0 = 1st page
formField.StrokeColor = JSO.Color.black 'StrokeColor sets the border and text colours of the field
'2nd signature field 80 pixels to the right of the 1st signature field
coords = Array(TOP_LEFT_X + WIDTH + 80, TOP_LEFT_Y, TOP_LEFT_X + WIDTH + 80 + WIDTH, TOP_LEFT_Y - HEIGHT)
Set formField = JSO.addField("SignatureField2", "signature", 0, coords)
formField.StrokeColor = JSO.Color.black
If PDDoc.Save(1, outputPDFfile) Then
PDDoc.Close
AVDoc.Open outputPDFfile, vbNullString
AVDoc.BringToFront
MsgBox "Created " & outputPDFfile
AVDoc.Close False
Else
MsgBox "Unable to save " & outputPDFfile
End If
End If
End Sub