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

trustedFunction with VBA?

Hanfwurst
Registered: Dec 4 2008
Posts: 7
Answered

Hey my dear friends! :D

I'm a bit desperate here. I made a script with VBA (macro). [i](NOTE: VBA, not VB. I just stress this because, when I searched for solutions on the internet, some people sometimes seemed unaware of the fact, that it's not the same. Or at least I had the feeling that this is the case...)[/i] It worked pretty well and people are already using it. It mainly searches through a .pdf file and then, if it found a special word, it should add some pages with insertPages. (that's only roughly explained of course. I try to keep things simple for you guys! :D)
As I said, it worked pretty well. But now I have to add something new to the application and since I haven't developped the App for myselfe, but rather for other people, I didn't use the macro for quite a while.
I have installed Acrobat 9 Pro now, but developped was the macro with Acrobat 6. Because of this fact, Acrobat won't allow me to use the insertPages methode.
So, I read on the internet, that I could use trustedFunction. But I just don't know how to do it.
Here is a little code snippet:

...
 
Set AVDoc = CreateObject("AcroExch.AVDoc")
AVDoc.Open aPathDat2, speicherNameAttachment
Set PDDoc = AVDoc.GetPDDoc
Set jso = PDDoc.GetJSObject
 
With jso
...
If UCase(index) <> UCase(daten.Fields(6)) Then
                            'MsgBox "Index Falsch. IST: " + Index + " SOLL: " + daten.Fields(6)
                            funktionsAufruf = fehlerMeldungenIndex(daten.Fields(1), index, daten.Fields(6))
                        Else
                            zeichnungsPfad = daten.Fields(2) + daten.Fields(0) + ".pdf"
                            einfuegOrt = .numPages - 1
                            .InsertPages einfuegOrt, zeichnungsPfad
...
end with
...

I think that actually only the part with the .insertPages is important for you guys.
How can I make a trustedFunction? I found solutions containing something like this (from the Javascript for Acrobat API Reference):
myTrustedFunction = app.trustedFunction(
function()
{
<function body>
}
);

But I just don't know how to include this in my code! :(

I hope, this is enough information for you, otherwise tell me! ;)

Kind Regards,
Hanfwurst

P.S. Excuse me if I explained all a bit complicated. This is most certainly mainly because I'm not a native! ;)

P.P.S. I just noticed that I put this Thread in the Forms: Acrobat section instead of the Javascript section. I'm sorry! You can change that of course!

My Product Information:
Acrobat Pro 9.0, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
You don't include a trusted function in your code. Instead, you place it in a folder-level JavaScript file that would need to be installed on each user's machine. You can then call this function and any others from your code.

See this article: http://www.acrobatusers.com/tutorials/2008/10/js_using_trusted_functions/


George
Hanfwurst
Registered: Dec 4 2008
Posts: 7
Thank you very much for your answer, it sure raised my hope again! ;)

I managed to find out the Folder for the level scripts and your linke sure helped a lot in understanding the whole system. But the thing is now, that I just don't know how to call this function from VBA. How can I use this function now (from an external program, in my case outlook macro)?

I'd be thankfull for every hint or (even better) a code snippet. (BTW: Can you even say "code snippet" in English? In case you can't: What I mean is "Code example". ;) )

Hanfwurst
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Yes, "code snippet" makes sense in English.

Try calling the function like you would any other, for example:

jso.MyTrustedFunction()
George
Hanfwurst
Registered: Dec 4 2008
Posts: 7
Thank you very much George Johnson! It worked really good! You are my hero! ;)

Here is the Solution I made, in case someone's interested:

The useInsertPages.js file (in the javascript folder of Acrobat):
MyInsertPagesFunction = app.trustedFunction( function (myNPage, myCPath){ app.beginPriv(); // Explicitly raise privilegethis.insertPages ({nPage: myNPage,cPath: myCPath});app.endPriv(); });

And the call of the function:
...Set AVDoc = CreateObject("AcroExch.AVDoc")AVDoc.Open aPathDat2, speicherNameAttachmentSet PDDoc = AVDoc.GetPDDocSet jso = PDDoc.GetJSObject ...

With jso' einfuegeOrt = the page after which to insert the source document pages.' pruefAnwPfad = path to the PDF file that will provide the inserted pages.MyInsertPagesFunction einfuegOrt, pruefAnwPfadEnd With ...

Thanks alot again and have a nice day!

Hanfwurst