Finding and replacing text on a PDF page

I do make an AppleScript once in a blue moon. Most are very simple.

Currently I am aiming to identify one of several open Acrobat PDF documents that has a certain text string on its first page, then replace some page numbers in a table of contents list on that page based on page numbers retrieved from another PDF file.

So I have no clue how to perform the work of identifying the specific Acrobat file to begin with, and also I need to search the first page text to find the specific strings with the page numbers.
Once I get that text, I should be able to replace text as needed.

If scripting dictionaries had solid examples of how to call out the commands, it would help immensely.

Thanks for your help!

Hi. Text is often randomly shattered into fragments by conversion, so even finding strings in a PDF file won’t be reliable; you might chance upon hitting a few keywords. Editing a PDF via AppleScript is something of a pipe dream. You can automate editing the build files in a page layout program, such as InDesign or XPress.

Thanks for the hope!

I will persist anyway.

First step, I want to know how to do the find text syntax from the Adobe Acrobat AppleScript dictionary.

This is what the dictionary says:

So this is what I started with and of course doesn’t work:

tell application "Adobe Acrobat"
	set docname to name of active doc
	set text2find to "Contents"
	if find text text2find in page 1 of document docname then
		beep 3
	else
		beep 1
	end if
end tell/applescript]

So I get the error: "Adobe Acrobat got an error: text2find of page 1 of document "3022-O FL HIM Care Choice AUG20.pdf" doesn’t understand the “find text” message."