[python-win32] COM, Acrobat and JavaScript
Joshua Reynolds
joshuar@isogen.com
Mon, 04 Mar 2002 15:00:31 -0600
Problem:
The functionality that I need to use from Acrobat is on a javascript
object (returned type defined in the Automation interface as an
LDispatch*). I haven't had any problems using any of their other OLE
components through python, but when I try to use the root javascript
object -- or any other javascript objects accessed through it.
I can get at all of the attributes on the javascript objects, but if I
try to call a method on it, it fails.
Here is the full calling sequence that brings me to failure
>>> from win32com.client import Dispatch
>>> app = Dispatch("AcroExch.App")
>>> app
<COMObject AcroExch.App>
>>> pddoc = Dispatch("AcroExch.PDdoc")
>>> pddoc.Open("d:\\tmp\\cn_final.pdf")
1
>>> jso = pddoc.getJsobject
>>> jso
<COMObject <unknown>>
>>> jso.app.formsVersion
5.0
>>> jso.console.Show
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File
"D:\programs\Python2.2\lib\site-packages\win32com\client\dynamic.py",
line 432, in __getattr__
raise pythoncom.com_error, details
com_error: (-2147467263, 'Not implemented', None, None)
in the above, app.formsVersion is an attribute, and console.Show is a
parameterless method.
Here are some potentially useful snippets from the Acrobat docs on using
the JSObject in Visual Basic.
6. JSObject always returns values as Variants. This includes property
gets as well as
return values from method calls. An empty Variant is used when a null
return value
is expected. When JSObject returns an array, each element in the array
is a
Variant. To determine the actual data type of a Variant, use the utility
functions
IsArray, IsNumeric, IsEmpty, IsObject, and VarType from the Information
module of the VBA library.
7. JSObject can process most elemental Visual Basic types for property
puts and
input parameters to method calls, including Variant, Array, Boolean,
String, Date,
Double, Long, Integer, and Byte. JSObject can accept Object parameters,
but only
when the Object was the result of a property get or method call to a
JSObject.
JSObject fails to accept values of type Error and Currency.
I have verified that I can access the methods on JSObject as well as
subObjects, but I would really really like to be able to use this stuff
through python.
Any ideas on how i can get access to any of those methods?
Thanks,
Joshua
--
Joshua Reynolds | Consultant
Isogen International
Office: 512-302-9879
Main: 512-380-0347
Cell: 512-743-3865
1016 La Posada Suite 240
Austin, TX 78752