Friday, 12 March 2010

Setting a default document when a PDF Portfolio is opened

We often get asked how to "turn off" the Flash Navigator panes for PDF Portfolios, or rather to show one member document when the PDF is opened, instead of the grid view, home or detail panels.

Users can still go back to any of those from the menu bar, but displaying a default document is often important (for example to show a cover letter or EULA).

Unfortunately, hiding the Navigator isn't something you can do from a menu in Acrobat - not yet. You need to talk to Acrobat via the all-powerful JavaScript console, and tell it what to change. It's not as scary as it sounds, but first-timers will have never worked this out themselves...

Open your Portfolio in Acrobat Pro and make sure you're looking at the Navigator, not at one individual member document, and press CTRL-J or Command-J to open the JS console. Press ENTER once to wake it up, then clear the messages using the trashcan icon in the bottom right corner. You are now talking to Acrobat, and the first thing to tell it is that you want the Navigator to open in "hidden" mode. Type this into the console, make sure your cursor is still at the end of the line, and press ENTER:


this.collection.initialView = 'Hidden';


The reply will be "Hidden". Nothing on the screen will change, but don't worry. You can clear the window again if you want, or just press RETURN a few times to get into empty space again.

UPDATE: We've been asked how to reset the view back to the original "navigator" system - the answer is to run

this.collection.initialView = 'Custom';


To set which member document is displayed when the Portfolio first opens, we need to set the .initialDoc property of the collection. Again, you can't (yet) set this from inside the user interface - it's time to type something else into the JS console! If you have a file called "my_first_letter.pdf" in the top level of your Portfolio, then to choose that you type this:


this.collection.initialDoc = "<0>my_first_letter.pdf";


Again, press ENTER to run it and you'll get the string back as a reply.

The logic is simple - .initialDoc wants the name of the member file, preceded by a number inside <>. For documents at the top level, that number is always zero - if your Portfolio has folders inside it, the number is the ID of the folder. Yeah, of course you need to work that out too, but the simplest way is to just list everything in your Portfolio and copy the one you want. If you run this one line of code, it'll show you everything:


for (var i=0; i<this.dataObjects.length; i++) console.println("DataObject["+i+"]="+this.dataObjects[i].name);


If you typed the above into the console over two lines, select both with your mouse and press CTRL-ENTER or CMD-ENTER to make sure the console runs both together. Remember, this only works at Navigator level, if you run the code while you're looking at a member document, it'll just see that document, and complain there's no member documents to list. You can put Portfolios inside Portfolios!

Copy and paste the name you want into the previous line of code, and run it. Save the Portfolio, and when it re-opens you'll have your default document in view. You can still carry on editing things, but if you tinker with the Navigator settings you may need to reset the initialView to "Hidden" again.

Alternately if you know which dataObject you want to open, you can use the object itself to set the initialDoc - for example typing this in the JS console will set the third document to be the default (remember arrays start from zero, so item [2] is the third in the list):


this.collection.initialDoc = this.dataObjects[2].name;


The order of files in the dataObject array is based on the order they were added (NOT their name, or any of the sort lists in the Navigator) - so if you plan on doing this hidden-view thing a lot, it makes sense to always add the document you want first. If it's a the same document (a cover letter, etc.) you can keep pre-saved "empty" Portfolios with that one document added and the view state set to Hidden, so you can just drop in the other files and save a copy.

Note that if you set the initialDoc, but leave initialView alone (or reset it to "Custom") the file you specify will be the one centered on the layout, for example in a Linear or Sliding layout, the navigator will set focus on whatever the file is. If it's in a subfolder, it will open that subfolder.

The techniques described here work in Acrobat 9 and Acrobat X, on both version 9 and version X portfolios. Setting the values of the collection object doesn't count as "editing", so you can apply them to an Acrobat 9 portfolio using Acrobat X without getting prompted to upgrade the layout.