我需要开发一个工具,该工具将pdf文件和字符串数组作为输入,并返回找到“ x”字符串的页码。
到目前为止,我已经能够在pdf中搜索字符串,但是我找不到找到返回其所在页码的方法
Sub SearchStringInPDF(searchString As String)
Dim PDF_path As String
Dim PathName As String
Dim pdfName As String
Dim waitTime As Date
PathName = [Path_name]
pdfName = [pdf_name]
If PathName = vbNullString Then
FullPath = ThisWorkbook.Path & "\" & pdfName
Else
If Right(PathName, 1) <> "\" Then PathName = PathName & "\"
PDF_path = PathName & pdfName
End If
Application.DisplayAlerts = False
'Open the pdf file
ThisWorkbook.FollowHyperlink PDF_path
'Wait time for a couple of seconds for the PDF file to fully load
waitTime = Now
'Send "CTRL + F" keys to the opened PDF to invoke find within that file
'The second argument "true" implies that Excel will wait for the keys to be processed
'before returning control to the macro.
SendKeys "^f", True
'Type the search string in the find box that opens
SendKeys searchString, True
'Hit enter to perform the s
SendKeys "{Enter}", True
Application.DisplayAlerts = True
结束子
示例: 为此pdf file 和这些字符串[“ acrobat distiller”,“避免迷失方向”,“ CERN”]
预期输出应为:
[第1页,第3页,第2页]