First Impressions: Setting the Viewer Preferences in a PDF File

Sample of the Week:

One of the primary goals of PDF is to preserve document fidelity independent of device, platform, or the software being used to view it. But, according to the PDF specification, a lot can still be left to chance; the ViewerPreferences entry in a document controls the way the document is presented on the screen and can affect the way it’s printed. If the ViewerPreferences entry doesn’t exist, PDF viewers present the document based on the current user’s preference settings. Generally end users don’t modify the initial view settings of their PDF software but different PDF software may have different defaults. The software manufacturer may even decide to change the default viewing modes dramatically from one version to the next as Adobe did when they introduced Read Mode and the Heads-Up Display (HUD) in Reader X. Starting with Reader X, Read Mode is on by default when PDFs are opened in a browser… like it or not.
Fortunately, it’s easy to take control of the initial view of a PDF file as well as set some defaults that will be used to populate the print dialog. The “Initial View” tab of the Document Properties dialog in Adobe Acrobat can be used to allow your document to override the user preferences of the PDF viewer and make the document appear the way you, the author, want it to.

If you don’t like Read Mode and you don’t want your documents to open up that way when your audience downloads them, setting the initial view to show a navigation tab will cause the PDF file to open in the normal view mode. The best thing about this trick is that it works when you set the initial view to “Bookmarks Panel and Page” even if you don’t have any bookmarks in the document.

If you are creating your PDF files programmatically or assembling them from files that you haven’t originally created and you need to control the initial view, the Datalogics PDF Java Toolkit precisely matches the capabilities of Adobe Acrobat. The SetViewerPrefs sample demonstrates how to use the PDFCatalog and PDFViewerPreferences classes to set the page mode, page layout, initial view, and printing defaults.

Code Snippet:

PDFCatalog catalog = doc.requireCatalog();
PDFViewerPreferences viewerPrefs = catalog.getViewerPreferences();
if (viewerPrefs == null){
        viewerPrefs = PDFViewerPreferences.newInstance(doc);
ASName[] enforceEntries = new ASName[1];
enforceEntries[0] = PDFViewerPreferences.k_PrintScaling;

While not all PDF viewers respect the ViewerPreferences entry specified in a PDF document,  by taking the extra step of setting it, you have a better chance of ensuring a consistent user experience and creating a good first impression of your PDF file.

View and download the SetViewerPrefs  sample or get all the samples and documentation by requesting an evaluation of the Datalogics PDF Java Toolkit.

Share this post with your friends

Get instant access to the latest PDF news, tips and tricks!

Do you want monthly updates on the latest document technology trends?

By submitting the form, you agree to receive marketing emails from Datalogics. You may unsubscribe at any time. 

Like what you're reading?

Get Datalogics blogs sent right to your inbox!

By submitting the form, you agree to receive marketing emails from Datalogics. You may unsubscribe at any time.