J'ai un problème auquel j'ai trouvé une solution partielle.
Je recherche quotidiennement une liste de mots dans un document pdf. Ensuite, je dois enregistrer chaque page correspondante dans un fichier séparé, renommé en "même nom que le fichier original - mot trouvé - page #".
J'ai trouvé le script ci-dessous qui fait presque toutes ces choses mais demande une entrée du mot recherché.
Ce dont j'ai besoin, c'est de changer cela pour que la liste de mots soit contenue dans le script du code.
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