Find Text on PDF

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • J Mateus
    New Member
    • Oct 2011
    • 2

    Find Text on PDF

    Hi

    I am using a Web Browser control to display a pdf file and I would like to find a way to use the find functionality from the pdf viewer, using vba code, to find a tag inside of the pdf.

    In detail (see screenshot): I have one continuos subform (subform1) with record selectors. Whenever I click on a record on the subform1, I would like to use vba to get the string LineID and make a search on the pdf viwer using the "Find" tool.



    How can I pass the string "Line Id" from the subform to the web browser (pdf viwer) and automatically perform the search?
    Attached Files
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    There appears to be no easy way to accomplish this, but I did arrive at a rather bizarre solution involving SendKeys, a Programmed Delay, and simulated Keystrokes. I have tested it and it does work, but it may be a little flaky.
    1. Declaration in a Standard Code Module
      Code:
      Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    2. Code to execute:
      Code:
      'If nothing to find, get out!
      If IsNull(Me![txtFind]) Then Exit Sub
      
      Me![WebBrowser1].SetFocus           'Set Focus to the Web Browser Control (WebBrowser1)
      
      SendKeys "^f", True                 'CTRL+F will place Cursor in Find Box, in Browser (WAIT)
        Sleep 3000                        'Delay 3 Seconds
      SendKeys Me![txtFind], True         'Type in the Text in the Text Box txtFind on the Form (WAIT)
      SendKeys "{ENTER}"                  'Simulate pressing the ENTER Key
    3. Text indicated in [txtFind], if it exists in the *.pdf Document, will now be highlighted.
    Last edited by ADezii; Nov 24 '11, 10:09 PM. Reason: Added to Comments

    Comment

    Working...