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

How use Visual Basic .NET or Visual Csharp with the Acrobat SDK

whirpett
whirpett's picture
Registered: May 20 2010
Posts: 66

Hi,

I want control a pdf file with an application like Visual Basic....
I use the JSObject but it doesn't work....

An idea?

Thanks

thomp
thomp's picture
Expert
Registered: Feb 15 2006
Posts: 4411
What do you mean it doesn't work? Have you tried a simple test, such as acquiring the document path?

The best way to use the JSO is for calling folder level functions. There is a fundamental incompatibility between VB and JS. So writing VB code like it's JS code is generally a bad idea. Write the functionality you want to run in Acrobat as a folder level JavaScript function. Make sure it works within Acrobat by testing the function from a button on a PDF. Then call the function from the JSO.

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
whirpett's picture
Registered: May 20 2010
Posts: 66
Hi Thom and thank for your answer.

In fact, i use the ACROBAT SDK (9.1) and i found VB sample, and one particulary named : "ExecuteScriptIacVB", wich show how to execute a script by visual basic in a adobe windows.

To do easy, i want to execute a script by visual basic but in a VB windows....

Thanks
thomp
thomp's picture
Expert
Registered: Feb 15 2006
Posts: 4411
Where is the sample failing? on which bit of code?

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

whirpett
whirpett's picture
Registered: May 20 2010
Posts: 66
A part of code :


' get acrobat form object
Dim formApp As AFORMAUTLib.AFormApp
formApp = CreateObject("AFormAut.App")

' access fields object inside AcroForm.
Dim fields As AFORMAUTLib.Fields
fields = formApp.fields

' call the method to execute JavaScript
'ReturnString.Text =
fields.ExecuteThisJavascript(JScode.Text)


Execute a script (into the text area named : "JScode")....
And i want the same, but into a VB windows (but i just found the load file property to open this...)

Thanks
thomp
thomp's picture
Expert
Registered: Feb 15 2006
Posts: 4411
I'm not sure what you mean, did you solve your issue?

A PDF can be rendered in a VB window by using the AVDOC.OpenInWindowEx() function. This does't have anything to do with runing JavaScript. This fucntion simply renders the PDF display in an external 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
whirpett's picture
Registered: May 20 2010
Posts: 66
No i didn't solve my problem...

I start an adobe window and i execute a javascript. no problem
And start a VB window and executing a javascript its impossible ??? (if i understand your posts)

I see various library (acrobat.tlb, ...) and i find a component, "acrobat3D office insert" for 3D files
(my 3Dpdf come to a solidworks file).... but i don't think its the solution.

I'm lost ....
thomp
thomp's picture
Expert
Registered: Feb 15 2006
Posts: 4411
How do you start the VB Window? Acrobat has a different API depending on the ActiveX interface used. Take a look in the Reference.

http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/wwhelp/wwhimpl/js/html/wwhelp.htm?&accessible=trueThere's AcroExch and AxAcroPDFLib. You want to be using AcroExch.

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
whirpett's picture
Registered: May 20 2010
Posts: 66
Hi, Thom
Yes I use the AxAcroPDFLib to open a PDF file in my VB window (axAcroPDF1.LoadFile("xxx.pdf")), of course no problem.
But,with this library, i don't know how to execute a script into this window (axAcroPDF1).

And the SDK don't help me, because for every script, vb run an acrobat window....
thomp
thomp's picture
Expert
Registered: Feb 15 2006
Posts: 4411
AxAcroPDFLib is the same API used when a PDF is displayed in a browser window. It is a very thin API and does not provide access to many features. You'll need to use AxAcroExch. To open in a VB window use the AVDOC.OpenInWindowEx() function.

This will allow you to both display the PDF in a VB Window and to access the JS environment.

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
whirpett's picture
Registered: May 20 2010
Posts: 66
Thank thom,

But please, how use OpenInWIndowEx function?
I read documentation, but i don't found example, and my english is very bad.

i find this :

gAvdoc.OpenInWindowEx("C:\temp\plate.pdf", Me.Handle, 1, 1, 2, 0, 0, 100, 10, 10)

But how to use? and which component use?(acrobat reader, .... ?)

Thank
thomp
thomp's picture
Expert
Registered: Feb 15 2006
Posts: 4411
You'll find an example in the Acrobat 9 SDK which you can download from here:
http://www.adobe.com/devnet/acrobat/?view=downloads

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

whirpett
whirpett's picture
Registered: May 20 2010
Posts: 66
ActiveView?
whirpett
whirpett's picture
Registered: May 20 2010
Posts: 66
ok thom, i find.

An other question (i hope the last), to execute a script with adobe :

Dim formApp As AFORMAUTLib.AFormApp
formApp = CreateObject("AFormAut.app")
' access fields object inside AcroForm.
Dim fields As AFORMAUTLib.Fields
fields = formApp.Fields
fields.ExecuteThisJavascript("app.alert('test')")

(Take in EXECUTEIACJS in SDK) but now, how to do in my VB window? isn't AFormAut.app ....
thomp
thomp's picture
Expert
Registered: Feb 15 2006
Posts: 4411
There are C++ samples that use the OpenInWindowEX function, but it will work in VB. This function is not part of the Forms API. It's a different thing. Before trying to execute a script you'll need to first get the AcroExch API running and displaying the PDF in a VB 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
whirpett's picture
Registered: May 20 2010
Posts: 66
It's ok i run the PDf with the AcroExch API like the sample....
But now i don't success to execute a script inside!
whirpett
whirpett's picture
Registered: May 20 2010
Posts: 66
A piece of code :

Filename = "c:\temp\plate.pdf"



AcroExchAVDoc = CreateObject("AcroExch.AVDoc")

ok = AcroExchAVDoc.OpenInWindowEx(Filename, Me.Handle.ToInt32, AV_DOC_VIEW, True, 0, PDUseBookmarks, AVZoomFitWidth, 0, 0, 0)

If Not ok Then
MsgBox("Can't open file: " + Filename)
Exit Sub
End If


...................


run my JS


.............
thomp
thomp's picture
Expert
Registered: Feb 15 2006
Posts: 4411
Use the JSOject, AcroExch.PDDoc.GetJSObject()

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
whirpett's picture
Registered: May 20 2010
Posts: 66
Yes, i use the JSObject!
I read a lot of articles, and post in this forum (and your interventions)....
But nothing

I try :

AcroExchAVDoc.PDDoc.GetJSObject()
error : PDDOC isn't member of 'Acrobat CaCroAVDOC

Globales variable :

Public AcroExchAVDoc As Acrobat.CAcroAVDoc
Public nOpenWindows As Short
Public AcroExchApp As Acrobat.CAcroApp

My variable are incorrect?
thomp
thomp's picture
Expert
Registered: Feb 15 2006
Posts: 4411
The PDDoc has to be acquired from the AVDoc before it can be used. It's all there in the documentation and the examples. Look them over carefully.

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
whirpett's picture
Registered: May 20 2010
Posts: 66
Ok, i look again the sample....
whirpett
whirpett's picture
Registered: May 20 2010
Posts: 66
Effectively thom,
i don't see carefuly the sample

Dim AcroPDDoc As Acrobat.CAcroPDDoc
AcroPDDoc = AcroExchAVDoc.GetPDDoc()

I can execute command with this (getPage, GetTitle, ....)
For a javascript the library are AFORMAUT.lib (ok?)


Dim formApp As AFORMAUTLib.AFormApp
formApp = CreateObject("AFormAut.App")
'access fields object inside AcroForm.
Dim fields As AFORMAUTLib.Fields
fields = formApp.Fields
fields.ExecuteThisJavascript("app.alert('Toto');")

But how to combine this 2 libraries?

Regards
whirpett
whirpett's picture
Registered: May 20 2010
Posts: 66
Edit :

Dim AcroPDDoc As Acrobat.CAcroPDDoc
Dim jso As object
AcroPDDoc = AcroExchAVDoc.GetPDDoc()
jso.GetJsObject()
whirpett
whirpett's picture
Registered: May 20 2010
Posts: 66
Anyone help me???
thomp
thomp's picture
Expert
Registered: Feb 15 2006
Posts: 4411
If all you need to do is to run a script then there is no need for the Forms API. You can run the script using the JSO.

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
whirpett's picture
Registered: May 20 2010
Posts: 66
Yes, but how?
The jso run function ....
To execute a script (ex: app.alert() ) the SDK samples use AcroForm library.

With JSO i don't see which keyword,method, or function to run a script....
thomp
thomp's picture
Expert
Registered: Feb 15 2006
Posts: 4411
The best way to use the JSO is to create a folder level function for your script. Then call the function from the JSO. I'm pretty sure I covered this in my first post. You need to pay attention to the details. It's the only way you'll ever get working code.
You could also just use the JavaScript eval() function.

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

whirpett
whirpett's picture
Registered: May 20 2010
Posts: 66
ok thom, thank you very much.
With jso.AssScript i success to run a script...

PS : i don't success to run script a little complicated (like reference.firstChild or reference.parent) VB say me "General error" and nothing else. Its normal?

Thank you again thom
thomp
thomp's picture
Expert
Registered: Feb 15 2006
Posts: 4411
The VB and JavaScipt data types are only compatible for simple types such as strings and numbers. That's why it's best to put all you code into a folder level function. If the code can be run from the console window, then it can be run from a folder level script using VB.

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
whirpett's picture
Registered: May 20 2010
Posts: 66
Ok
(I don't sucess to translate "folder level function" in french.Its a function into Adobe or a file in .js format???)

PS : I sucess to run my code but only if this are cut in a lot of part.

jso.addscript("1", "abcdefg....")
jso.addscript("2","..... hiklmnop....")

If i try an other method my app crash.
thomp
thomp's picture
Expert
Registered: Feb 15 2006
Posts: 4411
Yes, a folder level function is code for a function that is in a JavaScript file.
Here are a couple of articles you might want to look at:
http://www.acrobatusers.com/tutorials/2006/folder_level_scripts
http://www.acrobatusers.com/tutorials/2008/10/using_trusted_functions

Congradulations on getting the script to run by adding it as a document level script. But this is not a very good approach because the code is now part of the PDF.

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
whirpett's picture
Registered: May 20 2010
Posts: 66
Ok its good,

And i work in a virtual machin, and the error is probably this... my memory are to weak to run the script....

Thank you again....