Reality Checked - Exists? = True (It does? Oh dear...)
Reality Checked - Exists? = True (It does? Oh dear...)
- Subject: Reality Checked - Exists? = True (It does? Oh dear...)
- From: has <email@hidden>
- Date: Tue, 11 Sep 2001 02:07:03 +0100
Hey Jerry,
OK, treat #1:
===============================
--NOTE: requires Sigma's Additions to mimic keyboard typing (since I don't
see any way to enter meta-info directly into Acrobat via AS)
--not very elegant, but it works perfectly well in practice.
--IMPORTANT: meta-information file should contain the meta-info in
TAB-delimted form: titleTABsubjectTABauthorTABkeywords (1 entry per line)
--IMPORTANT: each field in document info dialog takes 255 characters
maximum. You should add validation to your db app to check for this.
--NOTE: this script assumes that filename (sans ".pdf" extension) matches
meta-title exactly; if this is not the case, the lookupinfo() handler will
need additional work.
--Also bear in mind that filenames should be alphanumeric characters only
if you intend to put these files online, and that their length is limited
to 27 chars + extension. Your titles are not necessarily restricted this
way.
property tid : AppleScript's text item delimiters
--the folder containing the pdfs to process
set foldertoconvert to choose folder with prompt "choose folder containing
the files to convert"
tell application "Finder" to set filestoconvert to every file in
foldertoconvert whose name ends with ".pdf"
--the file containing the meta-information
set metainformationfile to choose file with prompt "choose file containing
filename info"
--read the meta-information db file
open for access metainformationfile
read metainformationfile from 1
set metainformation to result
close access metainformationfile
--turn contents of meta-information file into list form
set AppleScript's text item delimiters to return
set metainformation to every text item of metainformation
set AppleScript's text item delimiters to tid
--now process each pdf file in turn
repeat with eachfile in filestoconvert
--get the meta-information from the conversion
set stringtotype to lookupinfo(eachfile, conversioninfo)
if stringtotype is "" then
--do some sort of error logging here
log "Couldn't find meta-information for file: " & (eachfile as text)
else
--open the pdf file, update the meta-info, then close with save
updatepdf(eachfile, stringtotype & return)
log "Updated file: " & (eachfile as text)
end if
end repeat
set AppleScript's text item delimiters to tid
----------------------------------------------
on lookupinfo(eachfile, conversioninfo)
--get the title (i.e. filename minus ".pdf")
set AppleScript's text item delimiters to ":"
set title to text 1 thru -5 of (last text item of (eachfile as text))
set AppleScript's text item delimiters to tid
--retrieve the relevant meta-info
repeat with eachitem in conversioninfo
if eachitem begins with (filename & tab) then return eachitem
end repeat
return "" --return "" if meta info for this file wasn't found
end lookupinfo
on updatepdf(eachfile, stringtotype)
set lengthofstring to count of stringtotype
set textcount to 0
--bring Acrobat to the front
tell application "Acrobat 4.0"
activate
--open file
open alias pathtofile
--bring up document info dialog
type text "d" holding down command
--type in meta-info 20 chars at a time (Acrobat's limit)
repeat
type text (text (textcount + 1) thru (textcount + 20) of stringtotype)
set textcount to textcount + 20
if textcount + 20 > lengthofstring then exit repeat
end repeat
--type any remaining meta-info
if textcount lengthofstring then type text (text (textcount + 1)
thru -1 of stringtotype)
--close file with saving
close saving yes with linearize
end tell
end updatepdf
===============================
"But what does it do?" I hear you cry/scream/yelp.
Simple: it changes meta-information in pdfs via Acrobat.(It's a variation
on a script I posted last week in the 'Photo List' thread, which changed
filenames.) This'll handle the end of your planned process (which means
you've only got to figure out how to make your postscript files, then
you're home free).
Supply it with a folder full of freshly-distilled pdfs and a file
containing the meta-information for every PM doc you have; it'll do the
rest. I do recommend assembling a proper database of meta-information, if
you haven't already got one. Any decent db app should be able to export the
records as a TAB/CR-delimited text file - which is exactly what this script
needs. (Building a DB containing meta-info rather than simply typing it
into Acrobat yourself might seem like extra work, but I can guarantee it'll
save you a load of time and effort in the long run.)
It's not been checked, tested or debugged, so it won't necessarily work
right out of the box - but you can do all that yourself, I'm sure. You may
also wish to make it more robust (though it's not bad as-is) and add better
logging (imo, decent logging is very important in batch-processing tools;
I'd recommend logging everything with timestamps to a permanent external
logfile if I were you. It's not hard to write.).
has