Ask a Question related to Adobe Acrobat SDK, Design and Development.
-
Jon_Pyne@adobeforums.com #1
AcroExch.AVDoc.FindText()
Hi, there
Does anyone have any experience of the FindText() function? I was hoping to use it together with acrApp.MenuItemExecute "NewBookmark" to create a set of standard bookmarks. The API documentation claims that the function "Finds the specified text, scrolls so that it is visible, and highlights it" and it returns "True if the text was found, False if it was not." From my experience, though, it always returns True, and certainly doesn't scroll to the text or highlight it. In fact, all it seems to do is insert the find text in the application's search field.
Or am I doing summit wrong?
Dim acrApp, acrAVDoc
Set acrApp = CreateObject("AcroExch.App")
Set acrAVDoc = CreateObject("AcroExch.AVDoc")
acrApp.Show
If acrAVDoc.Open(MY_FILE, "") Then
acrAVDoc.FindText MY_TEXT, False, True, True
etc...
thanks
jON
- Adobe Acrobat 6.0
- MS Office 2003
- MS Windows XP Professional SP2
Jon_Pyne@adobeforums.com Guest
-
Printing document using AVDoc.PrintPages
Hello, I have used AVDoc.PrintPages to print PDF pages, it worked all fine until I upgraded from Adobe Pro version 7 to Adobe Std version 9. When... -
Duplicate AVDoc for the same PDDoc
Is it possible to duplicate an AVDoc and show it in an external Window? According to API Reference, „“Starting with Acrobat 7.0, it is possible to... -
Help with AcroExch.PDBookmark in VBA
I'm using the following subroutine in a Microsoft Access VBA module, which successfully opens a PDF document that is on the local hard drive: ... -
How to get the selected text in the FindText method? (In C#)
Hello, I need to get the selected text to make several checks using the method GetBoundingRect of the class AcroPDTextSelectClass. I have this... -
findtext immediately following the 'search' text
I have this code: Dim avDoc As New Acrobat.AcroAVDoc Dim avPV As Acrobat.AcroAVPageView ... -
Reinhard_Franke@adobeforums.com #2
Re: AcroExch.AVDoc.FindText()
Mmmh,
is my SDK (5.1) to old?
I would write:
$Ok = acrAVDoc.FindText MY_TEXT, 0, 1, 1
if $Ok = 1 then msgbox("Found")
MfG. Reinhard
Reinhard_Franke@adobeforums.com Guest
-
Reinhard_Franke@adobeforums.com #3
Re: AcroExch.AVDoc.FindText()
Mmmh,
I get true or false, but bothersome is, that when OK = false a msgbox appears and says "couldn't find".
You may play a little bit with that and perhabs use JSO for find/highlite in order to avoid that msgbox.
best regards, Reinhard
TestFind.vbs
---------------------------
Dim acrApp, acrAVDoc
Set acrApp = CreateObject("AcroExch.App")
Set acrAVDoc = CreateObject("AcroExch.AVDoc")
acrApp.Show
If acrAVDoc.Open ("c:\Test.pdf","") Then
Ok = acrAVDoc.FindText("SomeWhat", 0, 1, 1)
msgbox(Ok)
end if
set acrAvDoc = Nothing
set acrApp = Nothing
Reinhard_Franke@adobeforums.com Guest
-
Jon_Pyne@adobeforums.com #4
Re: AcroExch.AVDoc.FindText()
The return value is always True (or -1), whether the text is in the document or not. I've kind of given up on that working by itself, but am trying to use the fact that it plugs the string into a search and executes it. Where I am at now is...
acrAVDoc.FindText MY_TEXT, False, True, False = Now Do
DoEvents
Loop Until Now > i + 0.00001
acrApp.MenuItemExecute "SearchSubmenu, FindAgain" = Now Do
DoEvents
Loop Until Now > i + 0.00001
acrApp.MenuItemExecute "NewBookmark"
acrPDBookmark.GetByTitle acrPDDoc, "Untitled"
acrPDBookmark.SetTitle MY_TEXT
This is working as of now, but the whole system seems incredibly unpredictable. If I tweak something, it seems to break everything. Sometimes I get the search pane on the right; sometimes I don't.
Jon_Pyne@adobeforums.com Guest
-
Jon_Pyne@adobeforums.com #5
Re: AcroExch.AVDoc.FindText()
As I understood from somewhere, JSO is only good for searching for one word.
Jon_Pyne@adobeforums.com Guest
-
Reinhard_Franke@adobeforums.com #6
Re: AcroExch.AVDoc.FindText()
For me (AAv5) it works well.
Perhaps you have a look at this JS from my libary:
Loops through pages to find all word occurrence
//Paste this into your console, select all the text and hit ENTER on your keyboard
var wf = "Sales" //word to find
for (var i=0;i<this.numPages;i++){ for (var j=0;j<this.getPageNumWords(i);j++){ if (this.getPageNthWord({nPage:i,nWord:j}).toString() == wf){ app.alert("Found on Page: " +(i+1)) }}}
But it works realy only on one word (like "Sales",
but not: "Net Sales")
If that is already enough, we can use it with a vbs
Br, Reinhard
Reinhard_Franke@adobeforums.com Guest
-
Jon_Pyne@adobeforums.com #7
Re: AcroExch.AVDoc.FindText()
Thanks for your input Reinhard, but I need to search for a longer string. I'd get too many "hits" for one word.
I really wish I could understand why you get the right boolean returned, but I always get TRUE. Are you sure? Did you try searching for text that doesn't exist? Does it scroll to it, too, as promised?
Maybe I should downgrade... !
Jon_Pyne@adobeforums.com Guest
-
Reinhard_Franke@adobeforums.com #8
Re: AcroExch.AVDoc.FindText()
For me it works correct - I only dislike the msgbox "not found", when the value is false.
Another way would be be to read the text of the page(s) and anlyse it in VBS.
Attached a code snipet for that.
HTH, Reinhard
------------------------------
'// Save this as xxx.vbs and start with Double Click
'// It gives you the text of an already opened PDF
'// if Acrobat or no Doc is open you get an ErrorMsg
set WshShell = CreateObject ("Wscript.Shell")
WshShell.AppActivate("Adobe Acrobat")
WScript.Sleep 500
'// get the active Document
Set AcroApp = CreateObject("AcroExch.App")
Set AVDoc = AcroApp.GetActiveDoc
Set PDDoc = AVDoc.GetPDDoc
Set PdfPage = PDDoc.AcquirePage(1) '<<--SET in FILE! =Pagenumber Set PageHL = CreateObject("AcroExch.HiliteList") PageHLRes = PageHL.Add(0,9000) '<<--SET in FILE! (Start,END[9000=All]) Set PageSel = PdfPage.CreatePageHilite(PageHL)
for i = 0 to PageSel.Getnumtext - 1
pdfData =PDFData & PageSel.GetText(i)
Next
msgBox PDFDATA
Reinhard_Franke@adobeforums.com Guest



Reply With Quote

