Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combining a group of file into a single PDF (automation) (Acrobat 9)

Status
Not open for further replies.

Gruuuu

Programmer
Oct 7, 2008
543
US
Long story short, I'm kicking off most of this code from VBA in Excel, but I'll get to that later. First: I'm having trouble with running the javascript, and it seems like it's a fairly simple syntax issue, but only time shall tell.

The process goes something along the lines of this:
[tt]
Create new pdf document
Open/convert each file and insert pages from the file into new document
Close converted files
Save combined PDF
[/tt]

I can create a new document, no sweat, but when I call the code to open and convert a file, I run into problems. Here:
Code:
    Set jDoc = jApp.openDoc("C:\Users\xxxx\Documents\test.txt", "True")
I quickly learned that there were two things wrong with this: one that my Acrobat security settings did not like that, and that my syntax was wrong.

I started fixing the Security problem by reading through the Acrobat 9 JavaScript API. Well, turning on the setting to allow menu item execution wasn't the answer, so I added this to my Javascripts folder in my Adobe install folder:

Code:
    function tOpenDoc(fPath, bConv)
    {
	app.beginPriv();
	app.openDoc({ cPath: fPath, bUseConv: bConv });
	app.endPriv();
    };

    app.trustedFunction(tOpenDoc);

And to test I added this at the end:
Code:
    tOpenDoc({ cPath:"C:\Users\xxxx\Documents\test.txt", bUseConv: true });

Where the console pops up and tells me
[tt]
NotAllowedError: Security settings prevent access to this property or method.
App.openDoc:4:Folder-Level:App:trusted_functions.js
[/tt]

(If I call the function from my VBA code it just tells me the server threw an exception, which is marvelously helpful.)

anyhow, here's my entire VBA code if you care about that at all:

Code:
Sub test()

Dim app As AcroApp
Dim aDoc As AcroAVDoc
Dim pDoc As AcroPDDoc
Dim jso As Object
Dim jApp As Object
Dim jDoc As Object

Set app = CreateObject("AcroExch.App")

Set pDoc = CreateObject("AcroExch.PDDoc")
pDoc.Create
Set jso = pDoc.GetJSObject
Set jApp = jso.app


Set jDoc = jApp.tOpenDoc("{ cPath:""C:\Users\xxxx\Documents\test.txt"", bUseConv: true }")
    If pDoc.InsertPages(pDoc.GetNumPages - 1, jDoc, 0, jDoc.GetNumPages(), True) = False Then
        MsgBox "Nuh-uh Nancy"
    End If

End Sub

It obviously doesn't get past the tOpenDoc() call.
 
Update: the Acrobat 9 Javascript API says:
[tt]
[red]Note:[/red] (Acrobat 7.0) bUseConv can only be set to true during a console or batch event. See also Privileged versus non-privileged context.
[/tt]
Is this my issue? Researching Batch Sequences now to see if I can make that work, in the meantime I'll be checking back here.
 
General update:
I don't see a way to kick off a batch sequence through the JavaScript or through VBA. I assume that was the point of making some things only available during a batch event.
I'll research a couple other options but it's appearing like this isn't possible with my current limitations; however, I don't believe it is altogether impossible. If anyone has ideas, I'd love to hear them!
 
Solved my problem. Instead of using any javascript or settings from Acrobat, I instead used the default data models of VBA to convert all of the files I hope to see to either a powerpoint, word doc, or excel file. From that point I save them as PDF, and after that combine all the files. With VBA.

If anyone is interested in doing this outside of VBA and need a solution that does not require office to be installed, there was a glimmer of hope in locating the dll that makes the shell execute call. I found the DLL, and the call that it makes. The message is unfortunately encrypted though, and I really did not feel like decrypting it and figuring out how to add a list of files into that message.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top