|
Gruuuu (Programmer) |
18 Apr 12 12:11 |
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: Create new pdf document Open/convert each file and insert pages from the file into new document Close converted files Save combined PDF
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 NotAllowedError: Security settings prevent access to this property or method. App.openDoc:4:Folder-Level:App:trusted_functions.js
(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: CODESub 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. |
|