About Me:

Customizing PDF Portfolio Layouts
Part 6: Sorting

Sorting items in a PDF Portfolio


Introduction:

The focus of this article is to show you how to add the necessary code to your navigator to sort items in a PDF Portfolio.

By default, the initial sort is based on the "Name" field which corresponds to the filename of the attachment in the PDF Portfolio. However, you can use the "Specify File Details" panel to set the initial sort to whatever you like (see image to the right - click to enlarge). You can even add your own custom metadata fields through this interface or, as I discussed in my previous tutorial, you can add fields through the "navigator.xml" file.

The Obvious and the Hidden:

The list view (second icon below) of a PDF Portfolio is a completely separate navigator from the one you may have applied to the PDF Portfolio. This means that when you switch between list view and the Home (first icon below) view, your navigator is restarting every time. Ideally, your navigator will account for any changes that were made to the sort order when the user was in the list view.

Here are a few things to keep in mind about implementing sorting in your navigator.

  • The initial sort order of the PDF Portfolio is a property of the portfolio, not of the navigator that is applied to it.You can decide to either ignore the sort order specified in the PDF file or work with it. If you plan to ignore it, you can stop reading this... but then you'd miss all the fun.
  • The order of the items in the collection has nothing to do with the sort order. You'll need to detect the sort order and apply it to the collection every time the collection changes. The good news is, it's pretty simple to do once you understand the rest of these bullets.
  • When looking at a PDF Portfolio in the list view, you can sort the portfolio by clicking on the different column headings and can toggle them to be ascending or descending.What the interface does not tell you is that your clicks are assembling an array of sort criteria. If you are looking at the list view and the initial sort order is "Order" then you click on "Name" and then "Modification Date", your new sort order is the reverse of your clicks back to the initial sort; so it becomes "Modification Date", "Name", "Order". Click on "Order" again and the sort order becomes "Order", "Modification Date", "Name".
  • As of Acrobat 9.1, if you change the sort in the list view while in edit mode (the "Edit PDF Portfolio" panel is open), the initial sort is reset to that field and the file will be saved with that field as the new initial sort. If you are not in edit mode, the sort order will remain unchanged in the file and when you switch back to your navigator view, the sort will not be updated based on the list view. Basically, when you are in edit mode, your changes immediately affect the file. When you are not in edit mode, the changes to the sort order are for presentation only.

The Flex project linked to below demonstrates how to determine the sort order of the PDF Portfolio and then how to apply that to the collection. It also shows how to check if the file can be modified and then set the sort order to whatever you like if that's allowed.

The sort order is determined by the collection.sort array which is an ordered array of ISort instances.The collection.sort property is read/write so it's pretty easy to have your navigator set the sort order. When sorting the items in the PDF Portfolio, you also need to be cognizant of the field type in the ISort object. You'll see in the Flex project where I detect text, numeric and date types so that I can apply the correct type of compare function when sorting.

Conclusion:

Download this PDF file and try switching between the home view and list view and changing the sort order. If you have Acrobat 9, try doing it whith the edit panel open and closed and see what hapens to the sort order to better understand the concepts in this article.

Files:
The Acrobat 9 ActionScript SDK
Sorting items in a PDF Portfolio project