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

using VBA to open a PDF which includes trusted function "saveAs"

richp
Registered: Apr 25 2008
Posts: 2

Hi

I’m using a javascript (attached to a button) to loop through a tab-delimited text file, load in individual records to a pdf form, and then save these as individual pdfs. In order to do this, I had to define saveAs as a “trusted function” and save this to the javascripts folder of my Adobe program folder. Up to now it works fine.

My newest project has been to write VBA code in the Access application where the data actually resides to open the pdf. While I can get the pdf to open, the saveAs is not working. Any suggestions? (I've found some similar posts but haven't been able to glean the necessary information out of them)

Thanks,
Rich

This is the VBA:

Sub OpenAdobe()

Dim objAdobe As New Acrobat.AcroApp
Dim doc As New AcroAVDoc

objAdobe.Show
objAdobe.Maximize 1

doc.Open CurrentProject.Path & "\Vouchers\BatchVouchers10.pdf", "Vouchers"

End Sub

This is the (abbreviated) “trusted function”:

save = app.trustedFunction(
function(filename,type)
{
app.beginPriv();

if (type == "final") {

this.saveAs("Final/" + filename + ".pdf");
}

app.endPriv();
}
)

And this is the (abbreviated) relevant portion of the main javascript in the pdf:

switch(this.getField("Radio").value) {

case "Final":
save(filename,"final");
break;
}

My Product Information:
Acrobat Pro 7.0.9, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You can call a JavaScript function from a VB program through the JSO object. Like this. Assuming that a document is already open.

Dim jso As Object
Set jso = doc.GetJSObject
jso.save()

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