Acrobat 9

Has anyone here messed around with adding pages to a PDF in the new Acrobat 9? As far as I know, the only way to add pages to a PDF with Applescript is to actually open all of the pages and then insert behind the main one. I have not been working with applescript since 2008, so with the new Acrobat came new features that I am hoping will make it much easier to piece a PDF together.

My final result will (hopefully) find a file through a regular expression filename search and add the file as the last page of a new PDF. The folder the PDFs are in will have a couple hundred PDFs so opening all of them is not an option. I have the GREP part written but I am getting stuck when it comes to actually adding the pages.

Any help would be appreciated. :smiley:

Browser: Safari 531.9
Operating System: Mac OS X (10.6)

Hi,

I strongly doubt that it’s possible to manipulate PDF files without opening them.
The AppleScript dictionaries of Acrobat 8 and 9 look very similar

Whilst it is more than likely true it has been possible to open a file in Acrobat with invisible (don’t put activate in your code else it brings the menubar to the fore) Also don’t target Active Document as there is none use reference to document 1. This example works for me. and has done since about V6 or 7.

set x to choose file
--
tell application "Adobe Acrobat 7.0 Professional"
	open x with invisible
	set docRef to document 1
	tell docRef
		make new page at end
		if modified is true then
			save
close
		end if
	end tell
end tell

Biggest thing in 9 is being able to do fix-ups & optimize file to size thru preflight but thats in javascript.

Edit. Forgot the close (muppet!)

Mark67 : This worked for me in Acrobat Professional 9.3.1. Thanks!

I did encounter one issue that I haven’t worked out though. The file that I target for the ‘make new page at end’ seems to remain in use after the script has finished executing. I did close the file. It reminds me of ‘open for access’ when I’m writing a log file. Have you encountered this?

A couple of things:

  • Acrobat’s open command has a parameter called “invisible” that lets you open a file without showing it.

  • Referring to documents by index is different in Acrobat – document 1 means the first opened (of those still open), not necessarily the frontmost.

Sorry for hijacking, but this adresses my problem pretty good: how do you refer to the document you just opened via open “…”, even if there were several documents already opened? A little snippet to illustrate:

tell application "Adobe Acrobat Pro"
	set docRef to open ":Volumes:CI:CI Drees Design:¢ SKRIPTDATEN ¢:PD"
	close docRef
end tell

Don’t mind the obvious uselessness of the snippet, I’m just trying to focus on the problem. :slight_smile: I figured, I could use docRef to reference the file I opened, regardless of its document number, since I don’t know, how many documents are already open. But it just returns a “missing value”. When I try it like this:

tell application "Adobe Acrobat Pro"
	open ":Volumes:CI:CI Drees Design:¢ SKRIPTDATEN ¢:PD"
	close front document 
end tell

it just closes another open document, which tells me, the document I just opened is not made the frontmost document by default. So how can I reference it, then, not knowing its document number and not having a document reference to it? Am I missing something?

Thanks in advance for any help.

Model: Mac Pro
AppleScript: 2.1.2
Browser: Safari 534.50
Operating System: Mac OS X (10.6)

UPDATE:
I found kind of a workaround, but it seems a little…unsophisticated. The document is not being referenced directly but by counting all open documents and then referring to the total number, which is also the document number of the last opened document, of course:

tell application "Adobe Acrobat Pro"
	open ":Volumes:CI:CI Drees Design:¢ SKRIPTDATEN ¢:PD"
	set theDoc to count documents
	close document theDoc
end tell

So it’s working now, but my question from the last post still stands, I’m still thankful for any suggestions.

Hi,

as you have the name of the file, you could use this


tell application "Adobe Acrobat Pro"
	open "CI:CI Drees Design:¢ SKRIPTDATEN ¢:PD"
	close document "PD"
end tell

Edit: or easier


tell application "Adobe Acrobat Pro"
	open "CI:CI Drees Design:¢ SKRIPTDATEN ¢:PD"
	close active doc
end tell

Hi,

thanks for the quick reply. I should have mentioned, that I actually do not have the name of the file. The “PD” is just an alias to a file. I chose this way to make the script independent of the naming of the actual file, since it changes frequently (don’t ask! :slight_smile: ). The actual opened document has the name of the aliased file, though. You see my dilemma here?

As to your second script: it works. I take from this, that the active document doesn’t necessarily have to be the frontmost document. Is this safe to assume or are there any catches? Again, any advice is appreciated.

the active document is always the frontmost one, but it’s not automatically the document with index 1

Then this should work, even if there are previously opened documents:

tell application "Adobe Acrobat Pro"
	open ":Volumes:CI:CI Drees Design:¢ SKRIPTDATEN ¢:PD"
	do script theJava
	save front document to file saveOrdner
end tell

But it doesn’t. When there’s a previously opened PDF, this script will open the PD-document, correctly execute the JavaScript-commands on it (filling in a form) and then “ and here is where it gets weird “ save the PDF that was already open before the script was called under a new name and place.

After your last suggestion, I tried this:

-- ...
save active document to file saveOrdner
-- ...

which didn’t work. Curiously enough, this

-- ...
save active doc to file saveOrdner
-- ...

worked! Any ideas on the mechanics behind the doc/document-thing?

When you don’t want to use Acrobat you could use the command line utility ghostscript to merge pdf files.

front is a synonym for 1, in this case front document is equal to document 1,
which is not automatically the frontmost window in Acrobat.

active document as an adjective of document doesn’t exist in the language.
active doc is a property of class application

Hi DJ,
actually, I’m not trying to merge PDF files, I’m opening a PDF form template, fill in my information and save it to a certain spot under a certain name. I’m pretty comfortable with using Acrobat, only downside is having to resort to JavaScript to fill in the form, it’s sort of a break in the workflow. Would be nice to be able to do it all in Applescript.

Thanks for your time and very concise pointers StefanK, you helped me a lot.