Solved

How to Control an Adobe Reader Serach from VB NET 2005

Posted on 2007-11-27
3
2,222 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article is in response to a question here (http://www.experts-exchange.com/Other/URLs/Q_28283850.html) at Experts Exchange. The Original Poster has a scanned signature and wants to make the background transparent so that the signature may be pl…
Power PDF (http://www.nuance.com/for-business/document-imaging-and-scanning/power-pdf-converter/index.htm) is the newest product from the Document Imaging division of Nuance Communications (http://www.nuance.com/). It is available in two editions — …
In this third video of the Xpdf series, we discuss and demonstrate the PDFtoText utility, which converts PDF files into plain text files. Download and install the software.: You may have already downloaded and installed the Xpdf tools while watching…
Sometimes we receive PDF files that are in the wrong orientation. They may be sideways or even upside down. This most commonly happens with scanned or faxed documents. It is possible to rotate the view of these PDFs with the free Adobe Reader produc…

863 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

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now