I am trying to use automation with MS Access (VBA) 2007 to prime a PDF form with database values. I have seen multiple posts but I have been unable to get the last step to work - avoiding the "Save As" file dialog at the end.
Being new to the Acrobat object model, I may have missed a necessary step (and maybe I am approaching this in the wrong manner (FDF merge?).
I can get the code to run, and when I use a breakpoint, I can see that a form field is populated from code, but it just won't save.
I've reaearched this and tested code samples for over a day, but can't save a "populated" form
Any help would be appreciated.
Code follows:
Dim AcroApp As Acrobat.AcroApp
Dim AvDoc As Acrobat.AcroAVDoc
Dim pdDoc As Acrobat.AcroPDDoc
Dim fcount As Long
Dim sFieldName As String
Dim Field As AFORMAUTLib.Field
Dim Fields As AFORMAUTLib.Fields
Dim AcroForm As AFORMAUTLib.AFormApp
Set AcroApp = CreateObject("AcroExch.App")
Set AvDoc = CreateObject("AcroExch.AVDoc")
If AvDoc.Open("C:\AdobeAcrobatX\Forms\Book2.pdf", "") Then
'|==>Set pdDoc = AvDoc.GetPDDoc
AcroApp.Show
Set AcroForm = CreateObject("AFormAut.App")
Set Fields = AcroForm.Fields
fcount = Fields.Count
'MsgBox fcount
For Each Field In Fields
sFieldName = Field.Name
Debug.Print sFieldName
'Set Field = aformaut.Fields(TempFieldName)
If sFieldName = "_Rep" Then
Field.Value = Now()
End If
Next Field
'|==>Set pdDoc = CType(AvDoc.GetPDDoc, Acrobat.CAcroPDDoc)
'|==>Call pdDoc.ClearFlags(&H1)
'|==>Call pdDoc.Close
Call AvDoc.Close(0) '|==>Manually repond to "Save" dialog
Else
MsgBox "failure"
End If
AcroApp.CloseAllDocs
AcroApp.Exit
Set AcroApp = Nothing
Set AvDoc = Nothing
Set Field = Nothing
Set Fields = Nothing
I haven't done this for a while so I don't know if Acrobat X has new security restrictions that block silent save from the IAC. It might. And if that is the case then the way around this issue is to write a folder level trusted JavaScript function to perform the save, then call that function from the JSO in your VB app.
Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script