(Solved) – select first word/cell in next page of a pdf after a “findtext”

  • by

I’m trying to select the next page of a pdf after a search (first word on the next page), but I am not sure how to do this. So the findtext selects a word on page 29 then copies the page to the variable “content”, and then when I go to the next page using “gotonextpage1 = AcroPDPageview.Goto(nextpage1)” it seems to only change the page view, not actually select the next page (page 30). As a result of this i’m not able to progress in my code logic and the code doesn’t work through the do while loop as expected. Does anyone know how I can activate the next page so that when I run the findtext again it starts looking from the first word on the next page instead of continuing to search from where it left off?

                If AcroAVDoc.findtext(SearchString, False, False, False) = True Then
                    previouspage1 = AcroPDPageview.GetPageNum 'page29
                    pageno = Trim(Str(origpage))
                    dict(pageno) = 0
                    nextpage1 = AcroPDPageview.GetPageNum   1 'page30
                    gotonextpage1 = AcroPDPageview.Goto(nextpage1) 'acrobat goes to page 30 (but text selected on page 29 still)
                GoTo nextcase:
                End If

                Do While previouspage1 <> nextpage1 '29<>30 to start so it starts through loop
                        Set PageNumber = AcroPDDoc.AcquirePage(previouspage1)
                        Set PageContent = CreateObject("AcroExch.HiliteList")
                        If PageContent.Add(0, 9000) <> True Then Exit Function
                        Set AcroTextSelect = PageNumber.CreatePageHilite(PageContent)
                        On Error Resume Next
                        'selects everything on page i and copies to "content"
                        For j = 0 To AcroTextSelect.GetNumText - 1
                            Content = Content & AcroTextSelect.GetText(j)
                        Next j
                        'page 29 copied to clipboard

                        If AcroAVDoc.findtext(SearchString, False, False, False) = True Then 'this gives page 29 again not page 79 as it should as there's two
                        nextpage = AcroPDPageview.GetPageNum 'page 29 for some reason!       'references to the searched string on same page
                        pageno = Trim(Str(origpage))                                         'can't seem to get search to start from page 30.
                            If Not dict.Exists(pageno) Then
                            dict(pageno) = 0
                            End If
                        End If
                Loop 'now as 29 = 29, the loop is exited.

Leave a Reply

Your email address will not be published. Required fields are marked *