Add a one page PDF to multiple PDF's

I have a problem saving a one page PDF to multiple PDF"s that are in a folder. The multiple PDF’s are all different with about 8 to 10 pages. After the single PDF is inserted into the other PDF’s they are to be saved in a different folder which they are doing. Everything seems like it is working but the single page PDF is not being inserted before being saved to the end of the other PDF"s. I would also like to shut down Acrobat after all is done without the dialog box asking me if i want to save if possible.
This is what I have so far.

tell application "Finder"
	set source_folder to choose folder with prompt "Please choose folder containing Master PDFs "
	set Insert_File to choose file with prompt "Please select a PDF to be Added "
	--set Combined_Folder to source_folder & "Combined PDF:" as text
	set Combined_Folder to ((source_folder as text) & "Combined PDF:")
	if not (exists alias Combined_Folder) then
		set Combined_Folder to (make new folder at source_folder with properties {name:"Combined PDF"}) as text
	end if
end tell

---display dialog "Source Folder: " & source_folder as string  -- Only for testing
---display dialog "Combined Folder: " & Combined_Folder  -- Only for testing

---------------------------------------------------------------------------------------------

tell application "Adobe Acrobat Pro"
	open Insert_File
	set Insert_File to document 1
	set PageCount to count of pages of Insert_File
end tell
--display dialog "Insert File: " & Insert_File as string  -- Only for testing

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

repeat with this_file in file_list
	--display dialog "This File: " & this_file as string -- Only for testing
	set original_name to name of this_file
	set new_file_name to characters 1 thru -5 of original_name & "_NEW.pdf"
	
	tell application "Adobe Acrobat Pro"
		open (this_file as alias)
		
		insert pages Insert_File after PageCount from document 1 starting with 1 number of pages 1
		save document 2 to file ((Combined_Folder) & new_file_name)
		close document 2 without saving
	end tell
end repeat

Hi,

I’m not sure what’s the script supposed to do.
As far as I can see the script inserts page 1 of Insert_File after page of Insert_File(!)

To identify the documents reliably I recommend to assign a document by name to a variable rather than dealing with indices, for example


repeat with this_file in file_list
	--display dialog "This File: " & this_file as string -- Only for testing
	set original_name to name of this_file
	set new_file_name to characters 1 thru -5 of original_name & "_NEW.pdf"
	
	tell application "Adobe Acrobat Pro"
		open (this_file as alias)
		set original_document to document original_name

(*   other code        *)

		close original_document without saving
	end tell
end repeat


StefanK

The script is supposed to insert or combine a single page PDF file to every PDF file in a selected folder at the end of each PDF then save each one with original name Plus NEW added to the name…

Hope that helps with explanation of script.
thanks,
Polishprince

try this


set source_folder to choose folder with prompt "Please choose folder containing Master PDFs "
set Insert_File to choose file with prompt "Please select a PDF to be Added "
set Combined_Folder to ((source_folder as text) & "Combined PDF:")
tell application "Finder"
	set Insert_FileName to name of Insert_File
	if not (exists alias Combined_Folder) then
		set Combined_Folder to (make new folder at source_folder with properties {name:"Combined PDF"}) as text
	end if
	set file_list to every file of source_folder whose name ends with ".pdf"
end tell

---------------------------------------------------------------------------------------------

tell application "Adobe Acrobat Pro"
	open Insert_File
	set Insert_Document to document Insert_FileName
end tell

---------------------------------------------------------------------------------------------

repeat with this_file in file_list
	--display dialog "This File: " & this_file as string -- Only for testing
	set original_name to name of this_file
	set new_file_name to text 1 thru -5 of original_name & "_NEW.pdf"
	
	tell application "Adobe Acrobat Pro"
		open (this_file as alias)
		set original_Document to document original_name
		set lastPage to count of pages of original_Document
		tell original_Document to insert pages after lastPage from Insert_Document starting with 1 number of pages 1
		save original_Document to (Combined_Folder & new_file_name)
		close document new_file_name without saving
	end tell
end repeat
tell application "Adobe Acrobat Pro"
	close Insert_Document without saving
	quit
end tell

StefanK

Thank you so much. It works great.

Polishprince