1

I'm using Adobe Acrobat's COM interface to manipulate the contents of a PDF document hosted in a window provided by my application.

Adobe seem to have frozen development of the COM interface around 2006. Although Acrobat's type library provides access to a fairly limited set of functions, the COM interface doesn't provide direct access to many of the functions available in the Acrobat application's menus + toolbars. These days they expect you to be working via their JavaScript API.

The Acrobat type library enables you to get access to a JavaScript object associated with a particular document. For example, the following turns the first page of a document upside-down:

[...]
var
  Doc : CAcroPDDoc; // interface Acrobat document
  vJS : OleVariant; // access to JavaScript object  
begin

  Doc := CoAcroPDDoc.Create; 
  Doc.Open(AFileName);
  try
    vJS := Doc.GetJSObject;
    try
      vJS.SetPageRotations(0, 0, 180);
    finally
      VarClear(vJS);
    end;
  finally
    Doc := Nil;
  end; 

end;

That works fine where what I want to do just involves invoking a method of one of the objects in the Acrobat JavaScript API. My question is: How do I interface my application's code with the events some of these objects provide? E.g. there is a JS even which occurs when the user clicks a bookmark in the document - how would I go about providing an event handler for something like that?

I know how to implement an outbound interface and to connect it to a COM object via a ConnectionPointContainer/FindConnectionPoint. But I haven't a clue how to connect to a JS event on an object I'm accessing (via a call like GetJSObject above) that's on the other side of a COM object interface. So this isn't a case where I can "show my code so far", because I don't know where to begin.

MartynA
  • 30,454
  • 4
  • 32
  • 73
  • If I understand correctly you need to handle events for COM late-binding objects: http://stackoverflow.com/questions/3643463/delphi-createoleobject-events – kobik Aug 17 '14 at 11:01
  • @kobik: Hmm, thanks but what the answer to that q seems to be describing is what I'm used to doing for COM events where Delphi's typelib import doesn't generate events for the Delphi wrapper component. I don't think that's the problem though. What I'm wondering about is how to connect to JS events inside the object framework that the COM interface is connecting to. So, it's at one stage removed from normal COM events. It's not like the MSHTML typelib, which contains interfaces for receiving events from DOM elements - the Acrobat typelib doesn't surface any relevant events at all. – MartynA Aug 17 '14 at 11:29
  • I see what you mean. MSHTML has the `attachEvent`. I'm not familiar with `GetJSObject` (`JSObject`?) interface, but from reading a bit, it(?) should have a method `addEventListener`. which I believe will work with event sinking. – kobik Aug 17 '14 at 12:46

0 Answers0