使用QTP计算pdf文件中的字符串

发布于 2024-09-12 22:24:42 字数 651 浏览 2 评论 0原文

我正在尝试计算 pdf 文件中字符串存在的次数。我使用了下面的代码,但它陷入了无限循环。问题是在找到最后一页之后的字​​符串后,它返回到第一页并再次重复所有步骤。有没有人有解决这个问题的办法。任何帮助将不胜感激。

谢谢 湿婆

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()  

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()  

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遗忘曾经 2024-09-19 22:24:42

我不认为这与 QTP 有关,它与 Acrobat 的 API 有关,快速搜索返回 此 API 链接

看起来问题在于您正在为 bReset 使用布尔值,文档说:

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

所以 bReset 应该是一个 long 而不是布尔值。

bReset:如果为正数,则从文档的第一页开始搜索。如果为 0,则从当前页面开始。

在 VBScript 中,False 为 0,True 为 -1,因此当您发送 True 时,它可能不被视为正数,尝试使用 1 代替。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文