Tengo un problema para el que he encontrado una solución parcial.
Diariamente, busco una lista de palabras dentro de un documento pdf. Luego, necesito guardar cada página coincidente en un archivo separado, renombrado como "mismo nombre que el archivo original - palabra encontrada - página #"
He encontrado el script de abajo que hace casi todas esas cosas pero pide una entrada de la palabra buscada.
Lo que necesito es cambiar esto para que la lista de palabras esté contenida dentro del script en el código.
use scripting additions
use framework "Foundation"
use framework "Quartz" -- required for PDF stuff
--property theKey : ""
#===== Handlers
-- Supposed to create a new PDF file for every page from the passed PDF file which contains the key string.
on splitPDF:thePath forKey:theKey
set inNSURL to current application's |NSURL|'s fileURLWithPath:thePath
set thePDFDocument to current application's PDFDocument's alloc()'s initWithURL:inNSURL
# CAUTION. theList contain indexes of pages numbered starting from 1, but ASObjC number them starting from 0
set theCount to thePDFDocument's pageCount() as integer
repeat with i from 1 to theCount
set thePDFPage to (thePDFDocument's pageAtIndex:(i - 1)) # ?????
set itsText to (thePDFPage's |string|()) as text
if itsText contains theKey then
set newPath to (its addString:("-" & theKey & " -page " & text -2 thru -1 of ((100 + i) as text)) beforeExtensionIn:thePath)
set outNSURL to (current application's |NSURL|'s fileURLWithPath:newPath)
set newPDFDoc to current application's PDFDocument's alloc()'s init()
(newPDFDoc's insertPage:thePDFPage atIndex:0)
(newPDFDoc's writeToURL:outNSURL)
end if
end repeat
end splitPDF:forKey:
-- inserts a string in a path before the extension
on addString:extraString beforeExtensionIn:aPath
set pathNSString to current application's NSString's stringWithString:aPath
set newNSString to current application's NSString's stringWithFormat_("%@%@.%@", pathNSString's stringByDeletingPathExtension(), extraString, pathNSString's pathExtension())
return newNSString as text
end addString:beforeExtensionIn:
#===== Caller
set theKey to text returned of (display dialog "Enter the key to search for:" default answer "Manang Saling")
set thePath to POSIX path of (choose file with prompt "Choose a PDF file." of type {"PDF"})
its splitPDF:thePath forKey:theKey