PrintsPageRangeInAcrobat_1.02

UpDate to previous post: http://bbs.applescript.net/viewtopic.php?id=22475

I added a quit command.
I also fixed the line that calculates the “round (((AllPages / StepOff)) - 1)” part of the “repeat with i from 1 to round (((AllPages / StepOff)) - 1)” The math was wrong causing the program to continue printing past the last page in the pdf doc.

I added these 2 lines:

set Finish to (round ((AllPages / (StepOff + 1))))
repeat with i from 1 to Finish

Note: If you open and run this from Script Editor with the Event Log History open, it logs certain variable so you can see how it calculating the variables in order to check it as it runs.


(*Prints every n pages from acrobat
Revision: 1.03
Last Revised: 20070917*)

with timeout of 20000 seconds -- 5.55 hours to wait for response from user
	tell application "Finder"
		--display dialog "Before continuing, print a page from your Acrobat document to set up printer that you will use to print to." buttons {"Cancel", "OK"} default button 2
		
	end tell
	tell application "Acrobat 6.0.2 Professional"
		tell active doc
			display dialog "What is the starting page?" default answer ""
			set FirstPage to (the text returned in the result) as number -- Set starting page here
			display dialog "How many pages for each set?" default answer ""
			set StepOff to (((the text returned in the result) as number) - 1) -- The pages in each set to be printed
			set LastPage to FirstPage + StepOff -- This is the last page of the first set. i.e. if the first page is 1, and the range of pages in set was 8, then the last page will be 8 and so on.
			set AllPages to count of pages -- Gets all page in whole doc
			log "AllPages in doc: " & AllPages
			log "LastPage of 1st set: " & LastPage
			log "StepOff: " & StepOff
			log "FirstPage of 1st set: " & FirstPage
			
			
			set AllPages to AllPages - FirstPage + 1 --pages that are left to print, subtracts the starting page i.e. 1000 then adds one to include that starting page 
			log "AllPages in loop: " & AllPages
			set BoolVal to true
			
			set Finish to (round ((AllPages / (StepOff + 1))))
			repeat with i from 1 to Finish
				log "Finish: " & Finish
				print pages first FirstPage last LastPage
				
				if BoolVal is true then
					display dialog "Sent: " & FirstPage & " to " & LastPage & ". Continue with next " & (StepOff + 1) & " pages?" buttons {"Cancel", "Don't ask again", "OK"} default button 3 -- Asks user to continue so large page documents can be controlled if printer is needed by other people in office. If not needed you can comment out. 
				end if
				if (button returned of result) = "Don't ask again" then
					set BoolVal to false
				else
					if (button returned of result) = "Cancel" then
						quit
						
					end if
				end if
				set FirstPage to FirstPage + StepOff + 1
				set LastPage to LastPage + StepOff + 1
				log "StepOff: " & StepOff
				log "FirstPage of next set: " & FirstPage
				log "LastPage of next set: " & LastPage
				
				log "Count: " & i
				set i to i + 1
				
			end repeat
		end tell
	end tell
end timeout


Hey tlotzer,

This script is really useful. I’ve got a regular job that has multiple versions of an 8pp brochure in one combined PDF (comes from a web-2-print app) so I need to print in 8pp sections as well!

I did however come across a slight problem re-working your script for Acrobat 7. It wasn’t just a case of changing:

It seems there’s a problem with Acrobat 7 and the

command. You have to be more verbose for it to work.

ie: print pages first FirstPage last LastPage PS Level 3 without binary output and shrink to fit

credit to chuckles66 for that one: http://bbs.applescript.net/viewtopic.php?id=17469

Once that’s sorted it works like a dream! NICE ONE :cool:

Opps, also noticed a problem with the logic for the if statements here:


if (button returned of result) = "Don't ask again" then
set BoolVal to false
else if (button returned of result) = "Cancel" then
quit
end if
end if

seems to me you need to add an additional test otherwise these expressions are evaluated on subsequent loops:


if BoolVal is true and (button returned of result) = "Don't ask again" then
set BoolVal to false
else if BoolVal is true and (button returned of result) = "Cancel" then
quit
end if
end if

Still rock tho :smiley:

Browser: Firefox 2.0.0.7
Operating System: Mac OS X (10.4)