views:

27

answers:

1

I have an ActiveX control (Adobe PDF Reader) with a toolbar. This control doesn't expose some functions available through toolbar (mainly search function). I'm looking for a way to programmatically locate Search field on the toolbar, enter the text and invoke search (equivalent of pressing Enter in this field). What's most accurate way to make that? Found a solution based on System.Windows.Automation namespace, but couldn't get it to work correctly.

Thanks.

Here's the code I tried:

Dim pdfElement As AutomationElement = AutomationElement.FromHandle(AxAcroPDF1.Handle)
Dim condition As New AndCondition(New OrCondition(New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit), New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document), New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text)), New PropertyCondition(AutomationElement.IsTextPatternAvailableProperty, True))
Dim ac As AutomationElementCollection = pdfElement.FindAll(TreeScope.Descendants, condition)

For Each element As AutomationElement In ac

    If element.Current.Name = "Find" Then
        element.SetFocus()
        SendKeys.Send("TESTSEARCH")
    End If

Next
+1  A: 

Same answer as you previous question. The retail automation interface has the FindText() method. I already gave you the link to the API documentation.

Hans Passant
Hans, thanks for your answer. With that type of automation, will each user of my application need to purchase retail version?
Sphynx
No idea what the licensing terms are. Surely you'll find that at adobe.com somewhere. You're a bit too stingy to do it for you.
Hans Passant
I'm not worried about licensing terms right now, I'm wondering if it's technically possible to use full automation interface without forcing each user to purchase Adobe software.
Sphynx
Whether you can redistribute the retail runtime has *everything* to do with licensing terms.
Hans Passant
Hmmm... If that's permitted, any hint which files should be redistributed to make that possible?
Sphynx
I've downloaded full Acrobat version. Which COM should I reference instead of AcroPDF.DLL to use previously inaccessible methods (e.g. FindText)?
Sphynx