PDF to join

I am trying to join 2 or more pdf’s to a multipage pdf file. I am starting with several AI files.so for I’ve got

– Create the folder
set box to display dialog ¬
“Give this folder a name” default answer “NAME” buttons {“OK”}

set name_result to text returned of box ¬

–This is the Handler?
set folder_name to name_result

tell application “Finder” to make new folder at desktop
set my_folder to result as alias
tell application “Finder” to set the name of my_folder to folder_name

– Get a location for the exported files
set targetFolder to choose folder with prompt “Location for exported files”
set targetPath to (targetFolder as Unicode text)

tell application “Adobe Illustrator”
– Turn off user interaction so dialogs don’t cause the script to get stuck
set user interaction level to never interact

--	Count the open documents
set documentCount to count documents

--	Export each open document
repeat with i from 1 to documentCount
	--	Get the document's name to use for creating a file path to save to
	set documentName to name of document i
	--	Perform the save
	save document i in file (targetPath & documentName) as pdf ¬
		with options {class:PDF save options, preserve editability:false, printer resolution:75, optimization:true}
end repeat

end tell

Thanks for any help you can give me.

Hi Mike,
below is some existing code I wrote that uses Acrobat 7 to join/insert pages into a PDF. Is this the kind of thing you’re looking for? If you don’t have Acrobat 7 then this can still be done with some free third party apps and shell scripting.

set source_folder to choose folder with prompt "Please choose folder containing PDFs to insert"

set Master_File to choose file with prompt "Please select a PDF to insert pages into"

tell application "Finder"
	set original_name to name of Master_File
	set new_file_name to characters 1 thru -5 of original_name & "_new.pdf"
end tell

tell application "Finder" to set file_list to every file of source_folder whose name ends with ".pdf"

tell application "Adobe Acrobat 7.0 Professional"
	open Master_File
	set Master_Doc to document 1
	set PageCount to count of pages of Master_Doc
end tell

repeat with this_file in file_list
	if name of this_file is not original_name then
		tell application "Adobe Acrobat 7.0 Professional"
			open (this_file as alias)
			insert pages Master_Doc after PageCount from document 2 starting with 1 number of pages 1
			close document 2 without saving
		end tell
	end if
end repeat

tell application "Adobe Acrobat 7.0 Professional"
	save document 1 to file ((source_folder as string) & new_file_name)
	close document 1
end tell


Automator has a function to combine pdf pages and someone on this board (sorry I can’t remember who) located the python script that performs the action. It is located : /System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py

Anyway, here is a folder action script that I use to combine pdf’s :

property join_py : quoted form of "/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py"

on adding folder items to this_folder after receiving these_items
	tell application "Finder"
		set add_pdfs to ""
		set output_pdf to (name of this_folder as Unicode text) & ".pdf"
		get name of first item of these_items
		if result is output_pdf or result is (output_pdf & "_tmp") then error number -128 -- ignore false alarms
		set output_pdf to (POSIX path of (this_folder as alias)) & output_pdf
		repeat with an_item in these_items
			set add_pdfs to add_pdfs & space & quoted form of (POSIX path of (an_item as alias))
		end repeat
			get POSIX file output_pdf as alias -- it exists
			set name of result to name of result & "_tmp"
			do shell script "python " & join_py & " -o " & (quoted form of output_pdf) & space & (quoted form of (output_pdf & "_tmp")) & add_pdfs
			delete (POSIX file (output_pdf & "_tmp") as alias)
		on error
			do shell script "python " & join_py & " -o " & (quoted form of output_pdf) & add_pdfs
		end try
		repeat with an_item in these_items
			delete an_item
		end repeat
	end tell
end adding folder items to


Browser: Safari 412
Operating System: Mac OS X (10.4)