Solved

How to Control an Adobe Reader Serach from VB NET 2005

Posted on 2007-11-27
3
2,229 Views
Last Modified: 2013-11-26
HI All:

I have a program written in VB NET 2005 and from this program I would like to display a user's manual in PDF and have it automatically search for keywords, etc.  The search function is rather good in Adobe reader.
I am using the following object....

Dim WithEvents cadobehelp As New AxAcroPDFLib.AxAcroPDF

This provides functions to go to one location in the Page using Destinations (setnamesdest) (more on that later), but there is no "search" function.

So I tried to use senkeys and the equivalent, but it just is not working properly and it is a hack anyway.

Does anyone have any workaround to get the AxAcroPDFLib.AxAcroPDF object to perform a search on the document loaded?  Any suggestions?

Also, the PDF document that is being generated is from word using Acrobat.  This works well with bookmarks, etc, but one can not add destinations this way.  Any suggestions here would be appreciated.

This seems like a pretty straight forward thing to do (have a user's manual in PDF and then have soe automatic searching feature) but so far this has not been easy to do.

Thanks in advance.
0
Comment
Question by:ort111
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Author Comment

by:ort111
ID: 20387320
HI All, well it looks like I answered by own question.  The "best" way right now is to use the DDE interface to the Adobe Search Engine.  There is an example in the Adobe SDK in the VB section.  This will allow you to use a ddeproxy.dll to do the following Code.  This will perform a search on a word passed to the adobe help routine.  The search window will be found, brought to the front and a return send to finalze the ssearch.  

    Public Const GW_HWNDPREV = 3
    Private Const SW_SHOW = 5
    Private Const SW_RESTORE = 9

    Declare Function GetWindowTextLengthA Lib "user32" (ByVal hwnd As System.IntPtr) As Integer
    Declare Function GetWindowTextA Lib "user32" (ByVal hwnd As System.IntPtr, ByVal lpString As System.Text.StringBuilder, ByVal cch As Integer) As Integer
    Declare Function GetActiveWindow Lib "user32" () As System.IntPtr
    Declare Function GetForegroundWindow Lib "user32" () As System.IntPtr
    Declare Function FindWindowA Lib "user32" (ByVal zero As System.IntPtr, ByVal lpWindowName As String) As System.IntPtr
    Declare Function SetForegroundWindow Lib "user32" (ByVal handle As IntPtr) As Boolean
    Declare Function ShowWindow Lib "user32" (ByVal handle As IntPtr, ByVal nCmd As Int32) As Boolean
    Declare Function IsIconic Lib "user32" (ByVal hWnd As IntPtr) As Boolean

    Private Function GetActiveWindowTitle() As String
        Dim window_hwnd As System.IntPtr = GetForegroundWindow()
        'Dim windows_hwnd As Long = System.Windows.Forms.Form.ActiveForm
        ' See how long the window's title is.
        Dim length As Integer
        length = GetWindowTextLengthA(window_hwnd) + 1
        If length <= 1 Then
            ' There's no title. Use the hWnd.
            Return "<" & window_hwnd.ToString & ">"
        Else
            ' Get the title.
            Dim buf As String = Space$(length)
            Dim buf2 As New System.Text.StringBuilder(buf)
            length = GetWindowTextA(window_hwnd, buf2, length)
            Return buf2.ToString
        End If
    End Function
    Public Sub SetRegWindowForeGround(ByVal caption As String)
        Dim hwnd As System.IntPtr = FindWindowA(0, caption)
        Debug.WriteLine("Window Handle is ", hwnd.ToString)
        If Not IntPtr.Zero.Equals(hwnd) Then
            If IsIconic(hwnd) Then
                ShowWindow(hwnd, SW_RESTORE)
                SetForegroundWindow(hwnd)
            Else
                SetForegroundWindow(hwnd)
            End If
        End If
    End Sub
    Private Sub AdobeHelp(Optional ByVal word As String = "")
        System.Diagnostics.Process.Start(My.Settings.AdobeHelpFileName)
        Dim s As String = ""
        SrchDDEInitQuery()
        SetQueryWordTarget((word))
        SrchDDESendQuery()
        Application.DoEvents()
        ' wait for search to become(active)
        Me.SetRegWindowForeGround("Search")
        Dim i As Integer = 0
        s = GetActiveWindowTitle()
        While s <> "Search" And i < 655355
            s = GetActiveWindowTitle()
            i = i + 1
        End While
        System.Windows.Forms.SendKeys.Send("~")  ' need to send a return to perform search
    End Sub
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 20560948
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PaperPort is a popular document imaging/management product from Nuance Communications (http://www.nuance.com/). It is in widespread use by both individuals (http://www.nuance.com/for-individuals/by-product/paperport/index.htm) and businesses (http:/…
This article focuses on how to remove password security from multiple PDF files by Adobe Acrobat program. Sometimes it is essential to access the stored data items and to print, edit as well as copy content from Portable Document Format files in abs…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question