tags:

views:

111

answers:

2

Hi all,

I am trying to count the number of times a string exists in a pdf file. I used the below code, but it is going in infinite loop. The problem is after finding the string after the last page,it comes back to 1st page and repeats all the steps again. Does anyone have a solution for this problem. Any help will be appreciated.

Thanks siva

Dim AcroApp, AcroAVDoc  
Dim gPDFPath, bReset, nCount  
gPDFPath = "xyz.pdf"  

Set AcroApp = CreateObject( "AcroExch.App" )  
AcroApp.Show()  
Set AcroAVDoc = CreateObject( "AcroExch.AVDoc" )   
If AcroAVDoc.Open( gPDFPath, "" ) Then  
    AcroAVDoc.BringToFront()  
    bReset = True : nCount = 0  
    Do While AcroAVDoc.FindText( "let", True, True, bReset )   
        bReset = False : nCount = nCount + 1   
        Wait 0, 200  
    Loop   
End If  
AcroApp.CloseAllDocs()  
AcroApp.Exit()  
A: 

I don't think this is related to QTP it has to do with Acrobat's API, a quick search returned this link to the API.

It looks like the problem is that you're using a boolean for bReset, the documentation says:

VARIANT_BOOL FindText(BSTR szText, 
                      long bCaseSensitive, 
                      long bWholeWordsOnly, 
                      long bReset);

So bReset should be a long not a boolean.

bReset: If a positive number, the search begins on the first page of the document. If 0, it begins on the current page.

In VBScript False is 0 and True is -1, so when you're sending True it could be that it's not considered a positive number, try using 1 instead.

Motti
A: 

Hi Motti,

Thanks for the reply, i changed bReset it to 1,but still the problem is not solved. I m using acrobat professional trial version with QTP,is it anything to do with acrobat professional??

thanks siva

siva
siva - You should put replies/comments as comments, not as an "answer". Or you may want to edit your original post.
Tom E