Re: Parsing PDF; looking to count number of markup annotations
Re: Parsing PDF; looking to count number of markup annotations
- Subject: Re: Parsing PDF; looking to count number of markup annotations
- From: Chip Howland <email@hidden>
- Date: Thu, 18 Dec 2003 13:55:33 -0600
I'd like to come up with a way in Mac OS 9 to count the number of
annotations per reviewer in a PDF file. AppleScript seems like the only
solution. Unfortunately, Adobe Acrobat 5 has a fairly limited AppleScript
dictionary, which also seems to be largely broken. So, I've decided to
tackle the PDF file itself, rather then expect to get any help from Acrobat.
It seems pointless to check for "/Type /Annot" and "endobj", since
"/T (" is always contained in an Annotation object in my experience.
The script below should do what you want. It's not particularly fast,
but this task is more suited to Perl anyway. MacPerl of OS 9 could
probably do the job in under a second.
The script does not handle any sorting and you'll need to save it as
a script application.
on open theFiles
repeat with currentFile in theFiles
tell application "Finder" to set fileName to name of currentFile
set pdf_file to open for access currentFile
set theText to read pdf_file
close access pdf_file
set reviewerList to {}
set reviewerNameList to {}
set oldDelimiters to text item delimiters
set text item delimiters to " "
repeat with i from 1 to count paragraphs of theText
if paragraph i of theText starts with "/T (" then
if (words 2 thru -1 of paragraph i of theText as string) is
not in reviewerNameList then
set reviewerList to reviewerList & (words 2 thru -1 of
paragraph i of theText as string)
end if
set reviewerNameList to reviewerNameList & (words 2 thru -1
of paragraph i of theText as string)
end if
end repeat
set text item delimiters to oldDelimiters
set reviewText to fileName & ":" & return & return
repeat with reviewer in reviewerList
set reviewCount to 0
repeat with reviewerName in reviewerNameList
if reviewerName as string is (reviewer as string) then
set reviewCount to reviewCount + 1
end if
end repeat
set reviewText to reviewText & reviewer & ": " & reviewCount & return
end repeat
display dialog reviewText with icon note buttons {"OK"} default button "OK"
end repeat
end open
--
Chip Howland
http://www.skypoint.com/~howland/
So act that the maxim of your actions shall become
through your will alone a major motion picture.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.