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

create Script as Folderlevel that takes parameter(s)

lucaso
Registered: Feb 5 2008
Posts: 49
Answered

Trying to figure out how to write a 'documentlevel' script that does take a parameter (or preferably more). Using VB.NET-2005. (100+)Links are practically doing the same thing, want them to call a (not necessarily global) function, which can do several things, such as gotoNamedDest, reset bodercolors on annots on the page of the dest, and find a named annot, change it's bordercolor, so one can see what the link was about. To put the whole script in the link's setAction, is just too much......., should be much more simple.
jso.addScript("MyScript", "function Goto(d) {this.gotoNamedDest(d)}")
Link.setAction("MyScript('namedest')")
This will compile, but in the PDF it complains about 'missing formal parameter'.
What do I do wrong?

although pushing towards senior age, still want to keep up the pace

My Product Information:
Acrobat Pro 7.0.5, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The name of the function is "Goto()", not "MyScript". "MyScript" is the name of the Document Script.

Are you sure that the second line is correct? is "Link" a JavaScript link object? The JSO can have problems with JavaScript Objects.

Where is the named destination created? Does it really exist in the document?

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

lucaso
Registered: Feb 5 2008
Posts: 49
Are you sure that the second line is correct? is "Link" a JavaScript link object? The JSO can have problems with JavaScript Objects.
**JSo is the obtained JavaScriptObject and operates correctly.
Where is the named destination created? Does it really exist in the document?
**the nameddestinations do exist in the pdf, put in by commercial lib, saved and read in a second time to place the links and annotations.

So it should be the name of the actual function instead of its "nickname"?
Is it possible to have more then one parameter?
Something like:
Doc.addScript("DoSomething", "funtion GoTo(dest,pagenum,annotname) { this.gotonamedDest(dest); ResetBorders(pagenum);PaintBorder(annotname);}")
Link.setAction("GoTo(dest,pagenum,annotname)")

Why do I turn the JSO? The commercial lib does not create documentlevel scripts and has trouble with compound JS's. So trying to work out the best of 2 worlds...

although pushing towards senior age, still want to keep up the pace

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You can define your functions to have as many parameters as you'd like. Look up "function" definitions in any Core JavaScript reference for the details.

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

lucaso
Registered: Feb 5 2008
Posts: 49
Thank you for your help, Thomp.
I did find out why a function did not get accepted: even if there are no parameters, one should not forget the braces after the functionname (dummy!)
At least I got one hurdle out of the way....

although pushing towards senior age, still want to keep up the pace