Adobe Acrobat

Acrobat’s Applescript support is a gaping hole when taking the entire Creative Suite into account. All scripting support has been moved solely to Javascript or hidden in the Automate window (not Automator). Javascripts can be run via the Applescript APIs, but we can’t send arguments nor can we get values returned. Combine that with the difficulties surrounding Javascripts due to the myriad of PDF security issues and it makes me wonder why they even bother at all these days. Despite Adobe’s implementation, I have been able to squeeze some useful things.

Destructive cropping (CS4/v9)

This modifies the media box for each page in a PDF. Basically, in addition to all of the boxes shown in the Crop Pages window, there is another one called the media box. The crop box allows non-destructive cropping, but the media box enables destructive cropping. The crop box determines what is visible when the document is viewed, whereas the media box is a representation of the paper being printed on, so anything in the media box gets printed. If the media box is reduced and an object falls outside of the new size, then it will no longer get printed and is therefore removed. There is no “Oops!” after changing the media box, so use this judiciously and on a duplicate file of a given PDF.

tell application "Adobe Acrobat Pro"
	tell document 1
		set pageCount to (get count of pages)
		repeat with i from 1 to pageCount
			tell page i
				set cbox to crop box
				set media box to cbox
			end tell
		end repeat
	end tell
end tell

Goto Next Page in all open documents

Good for comparing multiple documents side-by-side.

tell application "Adobe Acrobat Professional"
	set lastDocument to (get count of documents)
	repeat with d from 1 to lastDocument
		set doc to document d
		tell doc
			tell PDF Window of doc
				goto next
			end tell
		end tell
	end repeat
end tell

Get count of bookmarks

Good for measuring exactly how much of your life was spent bookmarking PDFs. I’m not sure why anyone would want to know this outside of billing purposes.

tell application "Adobe Acrobat Professional"
	set thePDF to document 1
	set bookmarkCount to 0
	
	tell thePDF
		set bookmarkCount to get count of bookmarks
	end tell
	
	display dialog "Number of bookmarks: " & bookmarkCount
end tell