PDF cropping script needs fine-tuning

Hi all,

Ok, to begin with, I regularly get proof PDFs from a printer that look like this: http://www.veloce.co.uk/newsletter/rippedpdfexample.png
As the red lines in the example show, I want to crop them one by one and print each section (in this case, 8 sections).

To do this, I’ve created a very crude applescript that selects the folder of PDFs (all the same size) and then runs through a series of pre-prepared cropping instructions in Acrobat 7 Professional (using lots of tabbing!), chopping up the PDF one section at a time and printing it. The numbers in the script are entered into the relevant crop boxes, ie Top, Bottom, Right or Left. The script is on a Repeat, so it closes the PDF and opens the next one in the folder. It works fine, although on random occasions fails to enter the details and subsequently ruins the whole sequence.

Does anyone of a way of not having to use the GUI and all that horrendous tabbing? Currently it means I can’t use my computer while the script is running as Acrobat has to be on top. So far I’ve failed in instructing Acrobat to crop any other way “ I had hoped using Crop Box as a reference would have worked but so far, no luck.

Many thanks “ here’s the script (you will see it’s separated up into the 8 pages):

set folder_to_print to choose folder with prompt "Choose the folder of PDFs to crop and print."

set item_list to list folder folder_to_print without invisibles

tell application "Printer Setup Utility" to set a to name of printers
set b to (choose from list a) as text
tell application "Printer Setup Utility" to set current printer to printer b

repeat with print_item in item_list
	set the_alias to alias ((folder_to_print as string) & (print_item))
	
	tell application "Adobe Acrobat 7.0 Professional"
		activate
		open the_alias
		
		-- page 1 --
		tell application "System Events"
			keystroke "T" using command down & shift down
			delay 8
			repeat 5 times
				keystroke tab
			end repeat
			keystroke "606"
			repeat 2 times
				keystroke tab
			end repeat
			keystroke "289"
			keystroke return
			delay 8
		end tell
		tell application "Adobe Acrobat 7.0 Professional"
			print pages active doc PS Level 3 with shrink to fit
			delay 8
		end tell
		
		-- page 2 --
		tell application "System Events"
			keystroke "T" using command down & shift down
			delay 8
			repeat 5 times
				keystroke tab
			end repeat
			keystroke "406"
			repeat 17 times
				keystroke tab
			end repeat
			keystroke "205"
			keystroke return
			delay 8
		end tell
		tell application "Adobe Acrobat 7.0 Professional"
			print pages active doc PS Level 3 with shrink to fit
			delay 8
		end tell
		
		-- page 3 --
		tell application "System Events"
			keystroke "T" using command down & shift down
			delay 8
			repeat 5 times
				keystroke tab
			end repeat
			keystroke "204"
			repeat 17 times
				keystroke tab
			end repeat
			keystroke "406"
			keystroke return
			delay 8
		end tell
		tell application "Adobe Acrobat 7.0 Professional"
			print pages active doc PS Level 3 with shrink to fit
			delay 8
		end tell
		
		-- page 4 --
		tell application "System Events"
			keystroke "T" using command down & shift down
			delay 8
			repeat 5 times
				keystroke tab
			end repeat
			keystroke "0"
			repeat 17 times
				keystroke tab
			end repeat
			keystroke "607"
			keystroke return
			delay 8
		end tell
		tell application "Adobe Acrobat 7.0 Professional"
			print pages active doc PS Level 3 with shrink to fit
			delay 8
		end tell
		
		-- page 5 --
		tell application "System Events"
			keystroke "T" using command down & shift down
			delay 8
			repeat 7 times
				keystroke tab
			end repeat
			keystroke "0"
			repeat 17 times
				keystroke tab
			end repeat
			keystroke "288"
			keystroke return
			delay 8
		end tell
		tell application "Adobe Acrobat 7.0 Professional"
			print pages active doc PS Level 3 with shrink to fit
			delay 8
		end tell
		
		-- page 6 --
		tell application "System Events"
			keystroke "T" using command down & shift down
			delay 8
			repeat 4 times
				keystroke tab
			end repeat
			keystroke "406"
			keystroke tab
			keystroke "204"
			keystroke return
			delay 8
		end tell
		tell application "Adobe Acrobat 7.0 Professional"
			print pages active doc PS Level 3 with shrink to fit
			delay 8
		end tell
		
		-- page 7 --
		tell application "System Events"
			keystroke "T" using command down & shift down
			delay 8
			repeat 4 times
				keystroke tab
			end repeat
			keystroke "205"
			keystroke tab
			keystroke "406"
			keystroke return
			delay 8
		end tell
		tell application "Adobe Acrobat 7.0 Professional"
			print pages active doc PS Level 3 with shrink to fit
			delay 8
		end tell
		
		-- page 8 --
		tell application "System Events"
			keystroke "T" using command down & shift down
			delay 8
			repeat 4 times
				keystroke tab
			end repeat
			keystroke "0"
			keystroke tab
			keystroke "606"
			keystroke return
			delay 8
		end tell
		tell application "Adobe Acrobat 7.0 Professional"
			print pages active doc PS Level 3 with shrink to fit
			delay 8
			close front document saving no
		end tell
	end tell
end repeat

display dialog "Finished" giving up after 3

Browser: Safari 531.9
Operating System: Mac OS X (10.6)

What comes to mind would be to import the PDF into InDesign or Quark and print from there. You could have a template that has the offsets/rotation set or apply them with the script. You end up with a multi-page document with each page of your imposition on a separate page ready for printing.

Hi, thanks for the reply, although I’m unfamiliar with how your suggestion would work (my Indesign skills don’t stretch that far!) How would Indesign chop up the pages? And would this mean you would have to export again to PDF before printing?

Many thanks.

Im at home at the moment so have NO access to a printer to test but here is an example of setting and moving the ‘crop box’ about a PDF. In this you should be able to replace my delay commands with your print ones.

tell application "Adobe Acrobat 7.0 Professional"
	tell active doc
		tell page 1
			set Media_Box to media box
			set My_Width to (item 3 of Media_Box) / 2
			set My_Height to (item 2 of Media_Box) / 4
			repeat with i from 4 to 1 by -1
				set crop box to {0, (My_Height * i), My_Width, (My_Height * (i - 1))}
				delay 2
			end repeat
			repeat with i from 4 to 1 by -1
				set crop box to {My_Width, (My_Height * i), (My_Width * 2), (My_Height * (i - 1))}
				delay 2
			end repeat
		end tell
		close saving no
	end tell
end tell

Mark67,

Many thanks for the cropping script you posted here “ works a treat!

Further to the script posted by Mark67, does anyone know of way of getting Acrobat to print in the background? i.e while the user gets on with something else in another program? Currently it has to print the active doc, bringing Acrobat to the front each time the next page is to be printed.

Cheers.