Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding Text In A PDF From An External Source (IE)

Status
Not open for further replies.

cwinans

Programmer
Mar 26, 2001
102
0
0
US
I was recently given the challenge to find a way to find text in a pdf file from out side the pdf viewer.

For example, there is a framed web page, on the left is a list of "bookmarks" which are all links from an html page.
The right frame is loaded with an PDF file. My employer wishs to be able to click on the link let it be a text link with '6' as the text. When he clicks on it a find operation is initiated in the pdf file. If '6' is found in the pdf file it will be highlighted.

Is there anyway to pass the pdf file a command to search for this? If you need anymore information please let me know. Thanks a bunch!! I hope this helped! ;-)
- Casey Winans
 
In several languages you can send keystrokes to another application. It is a little clunky but it does work. To my knowledge Acrobat does bot have a com object model that would allow you to do it programattically. That leaves your with sending key strokes. In VB the code would look something like this...

This codes loops through a VB recordset creating bookmarks in the PDF document... like I said it is clunky...


'make ACROBAT EXCHANGE current Application
AppActivate "Acrobat Exchange" 'error is trapped if not open
recCount = RStemp.RecordCount - RStemp.AbsolutePosition 'count of records
cLastSec = ""
cThisSec = ""
For myCount = 1 To recCount 'from current pos to end of set
cThisSec = Left(Trim(RStemp!Section), 2)
If cLastSec <> cThisSec Then
toAcrobat = newSpecDivision(cThisSec)
'find first division in heading
Debug.Print toAcrobat
SendKeys &quot;%{t}f&quot; + toAcrobat + &quot;%{f}&quot;, True 'search for division heading
SendKeys &quot;%{d}n&quot;, True 'create bookmark

End If
'Acrobat Exchange text search string
'these are dumb commands the program has no
'way of knowing if they were successfull.
'If an error occurs you will have to adjust the
'data and rebuild the Acorbat
'''toAcrobat = &quot;Section &quot; + Trim(RStemp!Section) + &quot; &quot; + Trim(RStemp!title)
toAcrobat = Trim(RStemp!Section) + &quot; &quot; + Trim(RStemp!title)
'the ( char gives trouble when sending
chkAcrobat = InStr(1, toAcrobat, &quot;(&quot;)
If chkAcrobat > 0 Then
toAcrobat = Left(toAcrobat, chkAcrobat - 1)
End If
'the ) char gives trouble when sending
chkAcrobat = InStr(1, toAcrobat, &quot;)&quot;)
If chkAcrobat > 0 Then
toAcrobat = Left(toAcrobat, chkAcrobat - 1)
End If
toAcrobat = Trim(toAcrobat)
Debug.Print toAcrobat
SendKeys &quot;%{t}f&quot; + toAcrobat + &quot;%{f}&quot;, True 'search for spec and title
SendKeys &quot;%{d}n&quot;, True 'create bookmark

cLastSec = cThisSec 'update division check
RStemp.MoveNext
Next myCount
RStemp.Close

-Pete
 
Pete

&quot;To my knowledge Acrobat does not have a com object model that would allow you to do it&quot;

VFP code to instantiate Acrobat Reader as a COM object is:-

oPDF = CREATEOBJECT([PDF.PDFCtrl.5])

I assume there must be an object model and relevant documentation somewhere.

Could anyone advise its whereabouts, please?

TIA HTH

Chris [pc2]
 
Pete

&quot;To my knowledge Acrobat does not have a com object model that would allow you to do it&quot;

You were right first time - you can create an object using the code in a preceding post, but that's the end of the road. HTH

Chris [pc2]
 
We developed a way to do this with PDF on both left and right frames - left PDF have a text box for performing searching and highlights in the right frame PDF.

We have gotten the best results by not mixing html and PDF whenever possible. HTML is fine for displaying PDF in the browser but leave the interactive features to pure PDF (Acrobat) javascripts.

sample @
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top