Re: (no subject)
Re: (no subject)
- Subject: Re: (no subject)
- From: Shane Stanley <email@hidden>
- Date: Tue, 19 Feb 2002 11:54:42 +1100
On 19/2/02 10:32 AM +1000, Pat Cannon, email@hidden, wrote:
>
Try this (you'll probably have to fix a couple line breaks):
>
--------------------------------------
>
on open pdfFile
>
set searchString to "CalGray"
>
set textFound to false
>
set chunkSize to 1024 -- read the file in chunks so as to not run out of
>
memory
>
set pointer to 1
>
repeat
>
try
>
set nextPointer to pointer + chunkSize
>
set pdfText to read pdfFile from pointer to nextPointer
>
if pdfText contains searchString then
>
set textFound to true
>
exit repeat
>
end if
>
on error -- I'm assuming the error is EOF
>
exit repeat
>
end try
>
set pointer to nextPointer
>
end repeat
>
if textFound then
>
beep 3
>
display dialog "This file contains the text "" & searchString & ""!"
>
buttons {"Get Debbie!"} default button 1 with icon stop
>
else
>
display dialog "This file does NOT contains the text "" & searchString &
>
""." buttons {"Cool."} default button 1
>
end if
>
end open
>
--------------------------------------
>
>
You can probably speed it up by making chunksize bigger -- this took a
>
minute and a half to read through a 4.8MB file on my G4.
But you're not allowing for the possibility of "CalGray" falling across the
boundary of two chunks. To be safe, you need to do something like store the
last paragraph of each chunk, then concatenate the next chunk to it each
time.
You would also speed things up a fair bit if you used "open for
access"/"close access"; as it stands, opening and closing being done
(automatically) each time you read. As a bonus, you would then no longer
have to keep track of where you were in the file -- you would just "read for
1024" each time.
--
Shane Stanley, email@hidden
_______________________________________________
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.