These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

PDF form data primimg with a Database

sys1jal
Registered: Mar 1 2011
Posts: 3
Answered

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

 

My Product Information:
Acrobat Pro 10.0, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Did you try using the pdDoc.Save() function? I don't see it in your code.

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

sys1jal
Registered: Mar 1 2011
Posts: 3
Thom,

Thanks for the reply.

I have at least 6 versions of the above code. I did try pdDoc.Save (pdDoc.Save 1, "C:\AdobeAcrobatX\Forms\Book2B.pdf") with no luck. The code runs but doesn't save the data in the fields.

I have written approximately 2 lines of JavaScript so far, so that is not an option unless you have some code samples and instructions that I can try.

Appreciate the help.

Joe
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
JavaScript isn't too difficult, You'll find most of what you need in this article:

Save with JavaScriptLook up the JavaScript Object in the IAC Reference. You can call the trusted function through the JSO in your VB app.



Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

sys1jal
Registered: Mar 1 2011
Posts: 3
Accepted Answer
Thom,

I tried it about 5 times and it seemd to be working. Saved by JavaScript (and kudos to you). I never would have gotten there by myself (at least not at this point).

Thanks again.

Joe