You've misunderstood Yvan's advice, and haven't followed Takaaki's code. You don't try to wrap it in an Acrobat tell block -- you use it instead of Acrobat. Unfortunately that's not the end of the story, because it won't honor the crop box and produce a cropped tif.
But you can use a variation on it to produce a cropped bitmap and then save that as a pdf file, without have to save any intermediary tif file. Again, this is instead of Acrobat:
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "Quartz" -- for PDFs
use framework "AppKit"
-- build file URLs
set originalPath to POSIX path of (choose file of type {"com.adobe.pdf"})
set originalURL to (current application's |NSURL|'s fileURLWithPath:originalPath)
set originalNameStub to originalURL's lastPathComponent()'s stringByDeletingPathExtension()
set destFolderURL to originalURL's URLByDeletingLastPathComponent()
-- read PDF
set aPDFdoc to current application's PDFDocument's alloc()'s initWithURL:originalURL
set pCount to aPDFdoc's pageCount()
-- work through pages
repeat with i from 1 to pCount
set thisPage to (aPDFdoc's pageAtIndex:(i - 1))
set theBounds to (thisPage's boundsForBox:(current application's kPDFDisplayBoxCropBox))
set theSize to |size| of theBounds
-- make image from page
set thisImage to (current application's NSImage's alloc()'s initWithData:(thisPage's dataRepresentation()))
if thisImage = missing value then error "Error in getting imagerep from PDF in page:" & (i as string)
-- crop by drawing into new image of crop size
set newImage to (current application's NSImage's alloc()'s initWithSize:theSize)
-- draw from original to new
newImage's lockFocus()
(thisImage's drawAtPoint:{0, 0} fromRect:theBounds operation:(current application's NSCompositeSourceOver) fraction:1.0)
newImage's unlockFocus()
-- create image view and add cropped image to it
set theView to (current application's NSImageView's alloc()'s initWithFrame:{{0, 0}, theSize})
(theView's setImage:newImage)
-- get PDF data from image view and save it
set theData to (theView's dataWithPDFInsideRect:{{0, 0}, theSize})
set outFileName to current application's NSString's stringWithFormat_("Page %@ %@.pdf", i, originalNameStub)
set outURL to (destFolderURL's URLByAppendingPathComponent:outFileName)
(theData's writeToURL:outURL atomically:true)
end repeat
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: