Copy link to clipboard
Copied
I have Adobe Acrobat DC and am attempting to extract data from fillable pdf forms into an access database using Visual Basic for Appliactions and Java Script. My routines allow users to select a form to import and it loop through all fields and imports data into a table in db. This part works fine. The issue I am having is that sometimes the signatures show up as the first objects in the field colleciton as "Signature1", "Signature2", "Signature3", etc... These are always the first indexes in the collection instead of in the location they show up on the acutal form. Some forms when imported the signature fields actually have the actual field name such as "ApprovalSig" (for approvers) or "PointSig" for point of contact as identified on the form and in the proper order.
Code: This code was originally obtained from theDBGuy's PDF Form Fields Demo at accessmvp.com/thedbguy and modified for my purposes
On Error GoTo errHandler
Dim appAcro As Object
Dim docAcro As Object
Dim docPD As Object
Dim jso As Object
Dim fd As Object
Dim strFile As String
Dim lngCounter As Long
Dim fName As String
Dim fValue As String
Set fd = Application.FileDialog(3) 'filepicker
'select PDF file
With fd
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "PDF Files", "*.pdf"
.Title = "Locate PDF file"
If .Show Then
strFile = .SelectedItems(1)
Me.lblFilePath.Caption = strFile
Set appAcro = CreateObject("Acroexch.AVDoc")
If appAcro.Open(strFile, "") Then
Set docPD = appAcro.getPDDoc()
Set jso = docPD.getJSObject
'clear previous field list
Me.txtFields = Null
If jso.numFields > 0 Then
For lngCounter = 0 To jso.numFields - 1
fName = jso.getNthFieldName(lngCounter)
If jso.getfield(fName).Type = "signature" Then
If jso.getfield(fName).SignatureInfo.Status <> 0 Then
fValue = jso.getfield(fName).SignatureInfo.Name & " " & jso.getfield(fName).SignatureInfo.Date
Else
fValue = "Signature Missing"
End If
Else
fValue = jso.getfield(fName).Value
End If
Me.txtFields = Me.txtFields & fName & "-" & fValue & vbCrLf 'Me.txtFields & jso.getNthFieldName(lngCounter) & "-" & jso.getfield(jso.getNthFieldName(lngCounter)).Value & vbCrLf
Next
MsgBox "Done!", vbInformation, "Demo"
Else
MsgBox "No form fields found!", vbInformation, "No Fields"
End If
'Close the PDF; the True parameter prevents the Save As dialog from showing
appAcro.Close True
Else
'unexpected Acrobat error
MsgBox "There was a problem reading the PDF file.", vbInformation, "Error"
End If
End If
End With
errExit:
'cleanup
Set fd = Nothing
Set jso = Nothing
Set docPD = Nothing
Set docAcro = Nothing
Set appAcro = Nothing
Exit Sub
errHandler:
MsgBox Err.Number & ": " & Err.Description
Resume errExit
Why would the field indexes when looping through fields change, perhaps based on what app was used to complete the form?
Any help appreciated
Copy link to clipboard
Copied
The fields in a PDF are indexed according the order they appear in the document level field list, no physical location. They change when the form is edited in such a way as to change this field list. AFAIK: It doesn't have anything to do with the appliction that is calling the JS, the fields are always in the same order.
Why is the order a problem?
On another note. You can make this code more efficient and robust by moving all of the JavaScript related functionality to a folder level JavaScript function in Acrobat. Then calling that function from the JSO. You could also order the fields in the function according to how you wanted it done.
Copy link to clipboard
Copied
NVM. I figured it out. Users were drawing signatures instead of using the digital signature blocks provided.