Making a droplet that sets "document properties" on pdf's

Hello,

i’m very new to AS. In fact I stumbled upon it while trying to figure out a workflow problem.
Now, i’m not too sure how to get started with this.

As the title implies, I need to create a droplet that will - when a pdf is dropped on it - set that pdf’s document properties to “Show: Pages panel and Page”, “Page layout: Single Page” and “Magnification: Fit Page”.

Now what i did find here is something to call a batch process, but this is annoying when i need to share this dropplet to my team mates.

Well if any of you has pointers, code embryo etc. :slight_smile:

Many thanks,

Ugo

Model: G4 PPC Dual 1.25Ghz
AppleScript: 1.10.7
Browser: Firefox 3.0.3
Operating System: Mac OS X (10.4)

I don’t think that those are properties that are stored in the document. If you are using Acrobat go to the page display preferences and set them there.

You can set a default in acrobat for when you open “unspecified” docs. But you can also bypass the user’s default by specifying those in the document.

Im almost certain that when you do this in the UI Acrobat is adding “document level” JavaScript to the file. This is then executed when the file is opened and overrides the user pref’s. If you can do this or can find who can do it with JavaScript then it should be possible to “do script” and perform this. The method you would need to look into is addScript()

Mark, i’m sure this is valuable input but, to be honest, I dont understand what you wrote :frowning:
From where i stand i’m not even sure how to begin this script let alone how to make it a droplet…

I don’t have adobe acrobat so I can’t help you with that. As such I don’t know if the following workflow is possible but I would guess that it is.

  1. open each dropped file using acrobat
  2. script acrobat to change the document settings
  3. script acrobat to save the file
  4. script acrobat to close the file

The following will get you started. Note that the “on run” handler is used when you double-click the application. When you drop files on the application the “on open” handler is used… that’s what makes it a droplet. So save the following as an application and you will have a droplet. All you need to do then is figure out the acrobat commands for steps 2-4 and add it to this script.

on run
	display dialog "This is a droplet, so drop some \"pdf\" files on me!" buttons {"OK"} default button 1 with icon 2
end run

on open droppedFiles
	repeat with aFile in droppedFiles
		tell application "System Events" to set ext to name extension of aFile -- get the file extension of the file
		if ext is "pdf" then -- make sure the file extension is pdf
			tell application "Preview" -- you can change this to adobe acrobat
				activate
				open aFile
				-- perform your code to insert your preferences for the file
				-- save the file
				-- close the file
			end tell
		end if
	end repeat
end open

Hi ugocrazy,

A lot of things in Acrobat can be automated with Javascript and Adobe also offers extensive documentation about this subject.

In the above mentioned document you can see (p. 68), that you can add Javascript code to a PDF document, which will be executed by Acrobat when it opens the document. And adding Javascript code is done with the addScript command:

var myDoc = app.newDoc(); var myJS = "app.alert('Hello World');"; myDoc.addScript("InitMsg",myJS);
The above code would create a new PDF in Acrobat and add a Javascript to it, which would display a ‘Hello World’ message right after the document is opened in Acrobat.

Now, we don’t want to display such a message, but rather set the initial zoom level of the PDF. On page 183 we can study the various zoom levels available via Javascript. An example:

// The following example sets the zoom type of the document to fit the page: this.zoomType = zoomtype.fitP;
As Acrobat’s AppleScript dictionary supports the «do script» command, you can execute the Javascript code from within AppleScript, which enables you to automate the whole task with a folder action.

I hope all that makes sense to you :lol:

Wow this is wealth of information Martin and regulus,
i will be looking iinto this this afternoon and most certainly will pester you with questions in the followind days :wink:
I feel it’s hard to begin searching when you dont know what to search for in the first place. Thank you so much for you valuable help

Well i had some fun trying to learn how to manipulate a pdf from javascript and AS but i cant get to understand some stuff.
See at first i tried using some javascript but it proved incomplete (or i can’t read and understand correctly). Then i opened the acrobat dictionary from script editor and found stuff that looked like they would do the trick.
I left some tryouts in comments so maybe one of you can see what i dont understand.
Obviously my problem is that i dont quite understad the logic phrasing to tell as to set a documents preperty to a certain value

Anyways here goes


on run
	display dialog "This is a droplet, so drop some \"pdf\" files on me!" buttons {"OK"} default button 1 with icon 2
end run

on open droppedFiles
	repeat with aFile in droppedFiles
		tell application "System Events" to set ext to name extension of aFile -- get the file extension of the file
		if ext is "pdf" then -- make sure the file extension is pdf
			tell application "Acrobat 6.0.2 Professional"
				activate
				open aFile
				--do script file "hiddenpath:ASsetPDF.js"
				--set page layout to "Single Page"
				--set view mode to "pages and thumbs"
				set page layout of aFile to "Single Page"
				
				save active doc
				close active doc
			end tell
		end if
	end repeat
end open

thanks (again :)) for you help

Of course I’m just guessing because I don’t have acrobat…

These commands probably have to be in a tell document block inside of the tell application block. So after the open command try the following.
tell document 1
set page layout to “Single Page”
set view mode to “pages and thumbs”
save
close
end

bleh this is getting nightmarish :frowning:

I reallised that using the dictionary gives me properties that work well but somehow they are not applied as properties of the document (so i can save the document with new defaults).
Using javascript worked but I cant figure out how to set every parameter; for instance I can set the page zoom but i cannot find a way to set the page layout to “single” and neither can I set the document so i shows the page panel. The documentation seems to talk about it but is not very clear on how to use the properties =/
This is what i found that resembles what i’m looking for but i can’t figure out how to construct the instructions to add as a script.

so far my js is like this (thanks to Martin Michel):

var pZoom = "this.zoomType = zoomtype.fitP;"; this.addScript("FitPage",pZoom);
if you have an idea or have struggled against this help is welcome :slight_smile:

U

What version of Acrobat are you using?

Acrobat 6.0.2 Professional

I too am struggling with some of the JavaScript documentation. So I went back and re-visited a GUI script option. I did a quick test with some pdfs and it appears to work. Getting access to the Magnification to “Fit Page” was the tricky bit. I did not test with lots of files so you would need to check for your self that the dialog box is the same with your files. This should contain get you all in the inital view options with the exception of “Open to” did not get the chance to get to that bit.

tell application "Adobe Acrobat 7.0 Professional"
	activate
	tell active doc
		tell application "System Events"
			tell process "Acrobat"
				try
					click menu item "Document Properties..." of menu 1 of menu bar item "File" of menu bar 1
					delay 1
					tell tab group 1 of group 1 of window 1
						click radio button "Initial View"
						delay 1
						-- User Interface Options
						(*tell group 1 of group 1 of group 1 of group 1 of group 1
						set a to get value of checkbox 3 -- "Hide menu bar"
						if a = 0 then click checkbox 3
						set b to get value of checkbox 2 -- "Hide tool bars"
						if b = 0 then click checkbox 2
						set c to get value of checkbox 1 -- "Hide window controls"
						if c = 0 then click checkbox 1
					end tell*)
						-- Window Options
						tell group 1 of group 2 of group 1 of group 1 of group 1
							(*set d to get value of checkbox 3 -- "Resize window to initial page"
						if d = 0 then click checkbox 3
						set e to get value of checkbox 2 -- "Center window on screen"
						if e = 0 then click checkbox 2*)
							-- This needs to be off to be able to set "Page layout"
							set f to get value of checkbox 1 --"Open in Full Screen mode"
							if f ≠ 0 then click checkbox 1
						end tell
						-- Document Options
						tell group 1 of group 3 of group 1 of group 1 of group 1
							-- Show Pages panel and Page
							set g to get value of pop up button 2
							if g = "Page Only" then
								click pop up button 2
								keystroke (ASCII character 31)
								keystroke (ASCII character 31)
								keystroke return
							else if g = "Bookmarks Panel and Page" then
								click pop up button 2
								keystroke (ASCII character 31)
								keystroke return
							else if g = "Attachments Panel and Page" then
								click pop up button 2
								keystroke (ASCII character 30)
								keystroke return
							else if g = "Layers Panel and Page" then
								click pop up button 2
								keystroke (ASCII character 30)
								keystroke (ASCII character 30)
								keystroke return
							end if
							delay 1
							-- Page layout Single Page
							set h to get value of pop up button 1
							if h = "Default" then
								click pop up button 1
								keystroke (ASCII character 31)
								keystroke return
							else if h = "Continuous" then
								click pop up button 1
								keystroke (ASCII character 30)
								keystroke return
							else if h = "Facing" then
								click pop up button 1
								keystroke (ASCII character 30)
								keystroke (ASCII character 30)
								keystroke return
							else if h = "Continuous - Facing" then
								click pop up button 1
								keystroke (ASCII character 30)
								keystroke (ASCII character 30)
								keystroke (ASCII character 30)
								keystroke return
							end if
							tell combo box 1
								-- Magnification Fit Page
								click button 1
								tell group 1
									keystroke tab
									keystroke tab
									keystroke tab
									keystroke "Fit Page"
								end tell
							end tell
						end tell
					end tell
					-- OK these settings
					click button 1 of group 1 of window 1
				end try
			end tell
		end tell
		close saving yes
	end tell
end tell