I need to develop a tool that takes as input a pdf file and an array of strings and returns the page number where the "x" string was found.
so far I have been able to search for a string in the pdf but I can not find a way to return the page number where it is located
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
End Sub
EXAMPLE: for this pdf file and these strings ["acrobat distiller","avoid disorientation","CERN"]
the expected output should be:
[page 1, page 3, page 2]