Solved

How to Control an Adobe Reader Serach from VB NET 2005

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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:/…
*Adobe Acrobat 9 was used for this article.  Particular steps may vary depending on software versions. Adobe Acrobat has many, many variables that my be utilized to customize your forms for clarity and ease of use. The Form Editing Tool will be y…
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…
We often encounter PDF files that are pure images, that is, they do not have text characters, but instead contain only raster graphics. The most common causes of this are document scanning software and faxing software/services that create image-only…

761 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