0

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
SharpAffair
  • 5,558
  • 13
  • 78
  • 158

1 Answers1

1

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
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Hans, thanks for your answer. With that type of automation, will each user of my application need to purchase retail version? – SharpAffair Aug 29 '10 at 13:40
  • 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 Aug 29 '10 at 13:53
  • 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. – SharpAffair Aug 29 '10 at 14:00
  • Whether you can redistribute the retail runtime has *everything* to do with licensing terms. – Hans Passant Aug 29 '10 at 14:24
  • Hmmm... If that's permitted, any hint which files should be redistributed to make that possible? – SharpAffair Aug 29 '10 at 14:40
  • I've downloaded full Acrobat version. Which COM should I reference instead of AcroPDF.DLL to use previously inaccessible methods (e.g. FindText)? – SharpAffair Aug 29 '10 at 15:43