Sorting items in a PDF Portfolio
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 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 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