Solved

How to Control an Adobe Reader Serach from VB NET 2005

Posted on 2007-11-27
3
2,221 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
Comment Utility
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
Comment Utility
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Update 21-May-2015: I temporarily removed the source code and the code snippets to make major changes to the program. Regards, Joe A recent question here at Experts Exchange piqued my interest, so I decided to provide a thorough solution and publ…
The Adobe PDF proprietary file format is recognized as secure and formulated. But these PDF files are also prone to corruption and any external threat like virus attacks, improper storage can hit PDF file integrity.This type of damages can make cruc…
In this video, we show how to perform Bates Numbering/Stamping of PDF documents using Power PDF Advanced, the newest product from the Document Imaging division of Nuance Communications. There are two editions of Power PDF — Standard and Advanced. Th…
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…

743 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

17 Experts available now in Live!

Get 1:1 Help Now