Print PDF with Acrobat and detect page size for page setup

Hi,

This is my first post as an applescript newbie, I’m hoping to make my workflow (as a designer) much quicker and stress free (well, less stressfull anyway!).

I’ve dabbled with folder actions and basic scripts but never immersed myself in it, never having the time but it appears I’ve found a real need for a script.

We use Quark 7.5 on Snow Leopard and have a major bug with printing from Quark, we expected it as Q7 isn’t officially supported on snow but we needed some of the OS features for our current workflow. The problem is that most of the time when we print from quark to any printer it crashes quark, or simply spools and then doesn’t print at all. This is down to a CUPS filter that is malfunctioning.

So we needed a quick and easy way to print. I came up with the idea of exporting an EPS/PDF and then using acrobat to print the file, which works perfectly.

My question after that arduous background detail is their a way to set up a folder action to print the PDF/EPS file, without the shrink to fit option and to automatically detect the correct page size and change page setup to reflect this?

I’ve come across a couple of the Acrobat Printing scripts on this forum, but I’ve no idea how to make any detect the acrobat page size and change the Print Setup dialog to match.

Hope someone can help us, there is a loads of people on the Quark forum going crazy and running to indesign because there is no fix on the horizon from Quark. Other than shell out and upgrade to 8!

All the best

Elliot

Model: Mac Pro 4,1
Browser: Firefox 3.5.5
Operating System: Mac OS X (10.6)

Try the publication scripting forum here:

http://publi-script.com/Forums/index.php?board=19.0

but with Acrobat you might have to use javascript, or so I’m told.

I do this. Acrobat will use the system default for its paper size unless it has been changed in the GUI by a user in that session. So from a script point of view its best to quit & restart Acrobat to ensure its using the system options. Once it is then you can open files check there size and with some if/else logic use a shell call to change the system defaults. I use A5, A4, A3 & A3 (with shrink if over this size) as my options.

It’s not a Folder action Script but you could adapt to suit.

I will give it a quick check over once I’ve found it and post back as I’ve not used in a while.

Is this what you’re looking for?

property dpi : 72
property unit : 2.54 -- set the value to 1 or 2.54 to get dimensions in inches or centimeters.

-- - HANDLERS
on Round_ConvertPixelToUnit(num)
	set num to (((num as real)/ dpi) * unit) + 0.05
	num div 1 + (((num mod 1) div 0.1) * 0.1)
end Round_ConvertPixelToUnit


-- - ROUTINE
set p2f to POSIX path of (choose file of type {"com.adobe.pdf", "com.adobe.encapsulated-postscript"})

set {h, w} to paragraphs of (do shell script "mdls " & quoted form of p2f & "| grep -Ei 'kMDItemPage(Height|Width)' | awk '{print $3}'")
set {h, w} to {Round_ConvertPixelToUnit(h), Round_ConvertPixelToUnit(w)}

Wow, this could be the way forward for us, apologies for my misleading comment, “how to make any detect the acrobat page size”

Really what I meant was for the script to detect the page size of the eps/pdf and then change the page setup to suit (without fitting to print). It would be good if the end user didn’t have to even touch acrobat, all they do is export from quark to a folder and it would be printed, on the correct sized paper.

I’ll definitely look at the code

Many thanks to all

Elliot

Im at work now this was the script that I still occasionally use should give you some idea on how to go about this:

-- Record the current printer and set printer choice
tell application "Printer Setup Utility"
	activate
	set Default_Printer to the current printer
	set current printer to printer "DC_3535_DC3535_Print"
	delay 0.5
	quit
end tell

-- Record the system default paper size
set Default_Paper to do shell script "defaults read com.apple.print.PrintingPrefs DefaultPaperID"

-- Adobe uses system prefs for print set up on launch
-- Flush any user changes made after this by quit & re-launch
tell application "System Events"
	if exists process "Acrobat" then
		tell application "Adobe Acrobat 7.0 Professional"
			quit saving ask
		end tell
	end if
end tell

-- Get list of PDF's
set Question to "Do you want to include all the subfolders" & return & "within your folder selection?"
set The_Dialog to display dialog Question buttons {"No", "Yes"} default button 1 with icon note

if button returned of The_Dialog is "Yes" then
	set Input_Folder to choose folder with prompt "Where is the top level folder of PFD's?" without invisibles
	tell application "Finder"
		try
			set File_List to (files of entire contents of Input_Folder whose name extension is "pdf") as alias list
		on error -- only one file
			set File_List to (files of entire contents of Input_Folder whose name extension is "pdf") as alias as list
		end try
	end tell
else
	tell application "Finder"
		set Input_Folder to choose folder with prompt "Where is the folder of PFD's?" without invisibles
		try
			set File_List to (file of Input_Folder whose name extension is "pdf") as alias list
		on error -- only one file
			set File_List to (files of Input_Folder whose name extension is "pdf") as alias as list
		end try
	end tell
end if

set PDF_Count to count of File_List
if PDF_Count = 0 then
	display dialog "Your folder selestion contains no PDF files to print!" giving up after 2
end if

-- Loop through the list of files
repeat with This_File in File_List
	tell application "Adobe Acrobat 7.0 Professional"
		activate
		open This_File
		tell active doc
			set view mode to just pages
			set zoom type of PDF Window 1 to fit page
			delay 1
			set MB_Size to media box of page 1 as list
			-- Points to millimeters Conversion
			set MB_Height to ((item 2 of MB_Size) / 2.834645) as integer
			set MB_Width to ((item 3 of MB_Size) / 2.834645) as integer
			-- Determine long & short edges
			if MB_Height ≥ MB_Width then
				set LE to MB_Height
				set SE to MB_Width
			else
				set LE to MB_Width
				set SE to MB_Height
			end if
			-- Count the pages this is to be used in the print range
			set Page_Count to count of pages
			set This_Fit to false
			-- Fits on A5 paper (less printer margins)
			if LE < 200 and SE < 138.5 then
				set This_Fit to true
				do shell script "defaults write com.apple.print.PrintingPrefs DefaultPaperID iso-a5"
				delay 1
				print pages first 1 last Page_Count PS Level 3 with binary output
			end if
			-- Fits on A4 paper (less printer margins)
			if LE < 287 and SE ≤ 200 and This_Fit is false then
				set This_Fit to true
				do shell script "defaults write com.apple.print.PrintingPrefs DefaultPaperID iso-a4"
				delay 1
				print pages first 1 last Page_Count PS Level 3 with binary output
			end if
			-- Fits on A3 paper (less printer margins)
			if LE < 410 and SE ≤ 287 and This_Fit is false then
				do shell script "defaults write com.apple.print.PrintingPrefs DefaultPaperID iso-a3"
				delay 1
				print pages first 1 last Page_Count PS Level 3 with binary output
			end if
			-- Scale output to fit on A3 paper (less printer margins)
			if LE ≥ 410 or SE > 287 then
				do shell script "defaults write com.apple.print.PrintingPrefs DefaultPaperID iso-a3"
				delay 1
				print pages first 1 last Page_Count PS Level 3 with binary output and shrink to fit
			end if
		end tell
		close active doc saving no
	end tell
end repeat

-- Set the printer choice back
tell application "Printer Setup Utility"
	-- activate
	set current printer to Default_Printer
	delay 0.5
	quit
end tell

-- Set the system default paper size back
do shell script "defaults write com.apple.print.PrintingPrefs DefaultPaperID " & Default_Paper

Many thanks for that,

I’ve changed the script for my purposes (we don’t use A5 and only have one printer) and added a folder action in automator so that when any pdf/eps file is dropped on the “TOPRINT” folder it is oriented correctly and printed.
Then the file is removed leaving the “TOPRINT” folder clear.


on run {input, parameters}
	
	set Default_Paper to do shell script "defaults read com.apple.print.PrintingPrefs DefaultPaperID"
	
	tell application "Adobe Acrobat Pro"
		activate
		tell active doc
			set view mode to just pages
			set zoom type of PDF Window 1 to fit page
			delay 1
			set MB_Size to media box of page 1 as list
			-- Points to millimeters Conversion
			set MB_Height to ((item 2 of MB_Size) / 2.834645) as integer
			set MB_Width to ((item 3 of MB_Size) / 2.834645) as integer
			-- Determine long & short edges
			if MB_Height ≥ MB_Width then
				set LE to MB_Height
				set SE to MB_Width
			else
				set LE to MB_Width
				set SE to MB_Height
			end if
			-- Count the pages this is to be used in the print range
			set Page_Count to count of pages
			set This_Fit to false
			-- Fits on A4 paper (less printer margins)
			if LE < 287 and SE ≤ 200 and This_Fit is false then
				set This_Fit to true
				do shell script "defaults write com.apple.print.PrintingPrefs DefaultPaperID iso-a4"
				delay 1
				print pages first 1 last Page_Count PS Level 3 with binary output
			end if
			-- Fits on A3 paper (less printer margins)
			if LE < 410 and SE ≤ 287 and This_Fit is false then
				do shell script "defaults write com.apple.print.PrintingPrefs DefaultPaperID iso-a3"
				delay 1
				print pages first 1 last Page_Count PS Level 3 with binary output
			end if
			-- Scale output to fit on A3 paper (less printer margins)
			if LE ≥ 410 or SE > 287 then
				do shell script "defaults write com.apple.print.PrintingPrefs DefaultPaperID iso-a3"
				delay 1
				print pages first 1 last Page_Count PS Level 3 with binary output and shrink to fit
			end if
		end tell
		close active doc saving no
	end tell
	do shell script "defaults write com.apple.printaperID " & Default_Paper
	do shell script "rm ~/Desktop/TOPRINT/*"
	
	return input
end run

Many thanks again to all who helped, this will enable Quark 7.5 users who have upgraded to Snow Leopard function!