Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to Control an Adobe Reader Serach from VB NET 2005

Posted on 2007-11-27
3
Medium Priority
?
2,239 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Update 21-May-2015: I temporarily removed the source code to make major changes to the program. Regards, Joe INTRODUCTION This article presents a solution to a question (http://www.experts-exchange.com/Programming/Installation/Q_28396542.html)…
PDF files have been in the limelight due to its unmatched features.  Personal documents, emails, business reports and eBooks are all converted into PDF files owing to peerless features provided by it. Adding watermark to a PDF file is a method to se…
In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

971 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