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 开发者_JAVA技巧
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()
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.
精彩评论