insert pages command for acrobat professional 8

I tried the following applecript to combine two pictures into one pdf file:


set initFile to (path to desktop as string) & "acrobatTest1:rma.pdf"
set infile to (path to desktop as string) & "acrobatTest1:rma1.png"

tell application "Finder"
	set theFile1 to initFile as alias
	set theFile2 to infile as alias
end tell

tell application "Adobe Acrobat Professional"
	open theFile1 without invisible
	open theFile2 with invisible
	set docRefA to the name of document 1
	set PageCount to count of pages of document 1
	set docRefB to the name of document 2
	insert pages document docRefA after PageCount from document docRefB starting with 1 number of pages 1 with insert bookmarks
end tell

and I get the following error message:

AppleScrit Error
Adobe Acrobat Professional got an error: document “rma.pdf” doesn’t understand the
insert pages message.

Can anyone help me to understand what I’m doing wrong?

Thanks.

Suwen

My environment: MacBook, Mac OS 10.4.10, Adobe Acrobat Professional 8.1.1
I tried the same script on Adobe Acrobat 6 and got the same error.

Model: MacBook
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Hi Suwen,
please give this a try:

set initFile to (path to desktop as string) & "acrobatTest1:rma.pdf" as alias
set infile to (path to desktop as string) & "acrobatTest1:rma1.png" as alias

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

tell application "Adobe Acrobat 7.0 Professional"
	open initFile --without invisible
	open infile --with invisible
	set Master_Doc to document 1
	set file_to_insert to document 2
	set PageCount to count of pages of Master_Doc
	insert pages Master_Doc after PageCount from document 2 starting with 1 number of pages 1
	close document 2 without saving
	save document 1 to file ((path to desktop as string) & "acrobatTest1:" & new_file_name)
	close document 1
end tell

This works for me in Acrobat 7 I haven’t had a chance to try it in 8 yet, please let me know how you get on!
Thanks,
Nik

Dear Nik,

Thanks for your help. Your code works like a charm! :slight_smile:

I would never have figured that out.

Suwen

Hi Suwen,
glad this is working for you. Just incase you wanted to import more than one PNG file in on go give this a try:

set source_folder to choose folder with prompt "Please choose folder containing images 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 & "_revise.pdf"
end tell

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

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
	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 repeat

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

Thanks,
Nik

Hi guys, I know it’s an old thread but thanks for your contributions on this.

Your scripts helped me to perfect my own utility to export JPEGs from Indesign and then combine them into a single PDF. Sometimes this is necessary when a file is complex and the regular PDF just doesn’t come down to an emailable size.

Acrobat is not so easy to script and it even seems a bit quirky. For example I had a lot of trouble using variables within Acrobat to refer to open documents (you have to save them as a PDF before you can refer to them with a variable) and I could not use the repeat counter as a variable to specify the page number to insert subsequent files after the last page of the master PDF document. I had to create a new variable from the page count.

So without further ado, here is my script.


set file_list to {}

--Get output folder and base filename
tell application "Adobe InDesign CC"
	activate
	display dialog "This script exports all pages to JPEG and combines them into a single PDF" & return & return & "Click OK to continue and select a destination folder."
	set output_folder to choose folder with prompt "Select output folder for JPEGs and final PDF"
	set doc_filename to name of document 1
	set DotOffset to offset of ".indd" in doc_filename
	set InterimFilename to the text 1 thru (DotOffset - 1) of doc_filename
end tell

--Make a copy of original JPEG export prefs
tell application "Adobe InDesign CC"
	set OrigJPEGprops to properties of JPEG export preferences
	
	--Ask user for desired resolution
	display dialog "Please enter the JPEG resolution" default answer "300"
	set JPEG_Resolution to text returned of result as integer
	
	-- Set JPEG export prefs to preferred values
	set properties of JPEG export preferences to {anti alias:true, embed color profile:false, export resolution:JPEG_Resolution, Exporting Spread:false, jpeg color space:RGB, JPEG export range:export all, JPEG Quality:maximum, JPEG Rendering style:baseline encoding, use document bleeds:false}
	
	--Get page count
	tell document 1 to set INDD_PPCount to the count of pages
end tell

--Export JPEGs from Indesign page by page, with unique filename
repeat with x from 1 to INDD_PPCount
	set x1 to x as text
	tell application "Adobe InDesign CC" to set properties of JPEG export preferences to {JPEG export range:export range, Page String:x1}
	set NewFilename to InterimFilename & "_page" & x & ".jpg"
	set FilePath to ((output_folder as text) & NewFilename)
	tell document 1 of application "Adobe InDesign CC" to export format JPG to FilePath
	set FilePathAlias to FilePath as alias
	set file_list to file_list & FilePathAlias
	set NewFilename to InterimFilename
end repeat

--Reset original JPEG export prefs
tell application "Adobe InDesign CC" to set properties of JPEG export preferences to OrigJPEGprops

--Create PDF file path
set PDF_Filename to InterimFilename & ".pdf"
set PDF_FilePath to ((output_folder as text) & PDF_Filename)

--Combine JPEGs into a PDF document using Acrobat
tell application "Adobe Acrobat Pro"
	activate
	repeat with page_counter from 1 to the count of file_list
		open item page_counter of file_list
		if page_counter is 1 then
			save document 1 to PDF_FilePath
			set Master_doc to document 1
		else
			--insert pages Master_doc after page_counter from document 2 starting with 1 number of pages 1
			--insert pages Master_doc after 1 from document 2 starting with 1 number of pages 1
			set PageCount to count of pages of Master_doc
			insert pages Master_doc after PageCount from document 2 starting with 1 number of pages 1
			close document 2 saving no
		end if
	end repeat
	save Master_doc
	close Master_doc
end tell

--Delete the working file JPEGs from the destination folde
tell application "Finder"
	activate
	repeat with i from 1 to the count of file_list
		delete item i of file_list
	end repeat
end tell

--Go back to Indesign and report
tell application "Adobe InDesign CC"
	activate
	display dialog "Your PDF has been created."
end tell

Hi,

I’m using this to assign a just opened document to a variable, it’s not necessary to resave the file


set pdfFile to choose file
set pdfFileName to name of (info for pdfFile) -- get the file name

tell application "Adobe Acrobat Pro"
	open pdfFile
	set myDocument to document pdfFileName
end tell