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

Return value into VB windows...

whirpett
Registered: May 20 2010
Posts: 66

Hi,

I use the JSObject to run a script in a VB windows. It's possibly to return a variable in VB?

Thanks

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
VB data types and JavaScript data types are only truely compatible for the scaler types, Numbers and Strings. Sometimes objects work and sometimes they don't. I don't usually try. The most robust strategy is to pack all your return data into a string, in the JavaScript function, and then parse it out on the VB side.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

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

whirpett
Registered: May 20 2010
Posts: 66
oki thom,

i write a javascript function, to return a string:

function reference(ref)
{
// Création du contexte
var Context = getAnnots3D(0)[0].context3D;
// La variable 'ref' prend pour valeur l'origine de l'arbre
var ref = Context.scene.nodes.getByName(ref);
return(ref.name);
}


VB side :
I use test = jso.addscript("reference('xxxx')")
(it's to easy i know, but i want to try and ..... surprise, it doesn't work).
I read the IAC doc, but if you have an idea.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
try this on the VB side:

test = jso.reference("xxx");

Before testing in the VB script, YOU MUST verify that the function works when run from the Acrobat Console Window.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

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

whirpett
Registered: May 20 2010
Posts: 66
Hum,
Yes my function work on acrobat ( i don't test with the acrobat console) but it works.

I test your code tomorrow. thanks again
whirpett
Registered: May 20 2010
Posts: 66
Sorry, i have 2 questions again,

I'm in my home, and i haven't doc here.

- It's possible to write a javascript function in an empty doc PDF ? ( to run it after .... in this document)
- It's possible to change the color of an object?

I repeat sorry if my questions have already been asked...
Thanks
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Yes, of course scripts can be added to an empty PDF. However you don't need to put any code into the PDF. I told you before that you need to put the function in a folder level script and I pointed you to an article on the topic. READ THE ARTICLES!!

Color is a different topic. Post it to a new thread.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

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

whirpett
Registered: May 20 2010
Posts: 66
Ok thom i've read your article, and test this :

jso.addScript("ref","app.alert('plus');" )
for try,
and when i run the script,
jso.ref()
the message box display, but my applications crash systematically.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Let me repeat, do not add the script to the PDF. Do not use the "jso.addScript()" function.

What you need to do is to write a FOLDER LEVEL SCRIPT. Put the function in the folder level script and then call the function from the "jso".

Here's an article on Folder Level Scripts:
http://www.acrobatusers.com/tutorials/2006/folder_level_scripts

You can also find examples of folder level scripts here:
http://www.pdfscripting.com/public/65.cfm

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

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

whirpett
Registered: May 20 2010
Posts: 66
Yes, i read this article and i try, but when i run my functions i have mistake.....
Calling are the same ?
whirpett
Registered: May 20 2010
Posts: 66
To precise, my VB code say me : "error getsannots3D is not defined".
My JS code work, and alert work too (but in acrobat window)
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The name of the function is "getAnnots3D" with a capital "A". If it's misspelled it won't work. But there also could also be a context problem.

Before testing the specific code you want to run you have to validate your methodology. Write a simple folder level function as a test. Make sure you can run it from the VB program. Then write a folder level function for the real code and make sure it works when executed from the console window.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

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

whirpett
Registered: May 20 2010
Posts: 66
I dont write correctly.

I try an alert, but it run in acrobat windows, and i don't know why....
whirpett
Registered: May 20 2010
Posts: 66
Its ok, i add code (to my original) and now its works.
Thanks thom