OK, this is proof-of-concept. Choose a file and it will search for all runs of numbers, highlight them, save as a new PDF, and return a list of records in the form:
{{pageNumber:1, foundStrings:{"21", "06", "2016", "4", "54", "21"}}, {pageNumber:2, foundStrings:{"21", "06", "2016", "4", "54", "21"}} ,...}
The code needs cleaning up and modifying to deal with your multiple searches, and hopefully packaged into a handler. But it should give you something to work with:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "Quartz" -- for PDF stuff
use scripting additions
set thePath to POSIX path of (choose file of type {"pdf"})
-- define search pattern
set {theRegex, theError} to current application's NSRegularExpression's regularExpressionWithPattern
:"\\d+" options
:0 |error|
:(reference)
-- make URL
set anNSURL to current application's |NSURL|'s fileURLWithPath:thePath
-- make destination URL
set oldName to anNSURL's lastPathComponent()'s stringByDeletingPathExtension()
set newName to oldName's stringByAppendingString:"-2.pdf"
set destURL to anNSURL's URLByDeletingLastPathComponent()'s URLByAppendingPathComponent:newName
-- open doc and count pages
set theDoc to current application's PDFDocument's alloc()'s initWithURL:anNSURL
set theCount to theDoc's pageCount() as integer
-- create list to hold results
set findInfo to {}
-- loop through pages
repeat with i from 1 to theCount
-- get page and its text
set thePage to (theDoc's pageAtIndex:(i - 1))
set theText to thePage's |string|()
-- do search
set theRanges to (theRegex's matchesInString:theText options:0 range:{0, theText's |length|()})
-- create list to hold contents of matches
set pageFinds to {}
-- loop through matches found
repeat with aFind in theRanges
-- get the range and start and finish indexes
set foundRange to aFind's range()
set theStart to foundRange's location
set theEnd to theStart + (foundRange's |length|) - 1
-- get the matched text
set end of pageFinds to (theText's substringWithRange:foundRange) as text
-- get bounds of the matched text
set startBounds to (thePage's characterBoundsAtIndex:theStart)
set endBounds to (thePage's characterBoundsAtIndex:theEnd)
-- combine to get word bounds; assuming they're on a single line
set wordBounds to current application's NSUnionRect(startBounds, endBounds)
-- make highlight annotation
set theHighlight to (current application's PDFAnnotationMarkup's alloc()'s initWithBounds:wordBounds)
(theHighlight's setMarkupType:(current application's kPDFMarkupTypeHighlight))
-- add to page
(thePage's addAnnotation:theHighlight)
end repeat
-- update result
set end of findInfo to {pageNumber:i, foundStrings:pageFinds}
end repeat
-- save new PDF
theDoc's writeToURL:destURL
-- return result
return findInfo