PDF Viewer Preferences

The following code sample shows how to set the viewer preferences of a PDF document.

using (FileStream inFile = new FileStream("PackingLightBrochure.pdf", FileMode.Open, FileAccess.Read))
{
    // open the source document
    Document document = new Document(inFile);

    // remove the current security settings
    document.Security = null;

    // assign a new ViewerPreferences object to document
    document.ViewerPreferences = new ViewerPreferences();

    // set viewer preferences
    document.ViewerPreferences.CenterWindow = true;
    document.ViewerPreferences.DisplayDocTitle = true;

    // hide UI elements in the viewer application
    document.ViewerPreferences.HideMenubar = true;
    document.ViewerPreferences.HideToolbar = true;
    document.ViewerPreferences.HideWindowUI = true;

    // show pages in two columns
    document.ViewerPreferences.PageLayout = PageLayout.TwoColumnLeft;

    // do not show the thumbnails or the bookmark tree
    document.ViewerPreferences.PageMode = PageMode.None;

    // write the modified document back to disk
    using (FileStream outFile = new FileStream("viewerpreferences.pdf", FileMode.Create, FileAccess.Write))
    {
        document.Write(outFile);
    }
}
Using inFile As New FileStream("PackingLightBrochure.pdf", FileMode.Open, FileAccess.Read)
   ' open the source document
   Dim document As New Document(inFile)

   ' remove the current security settings
   document.Security = Nothing

   ' assign a new ViewerPreferences object to document
   document.ViewerPreferences = New TallComponents.PDF.Navigation.ViewerPreferences()

   ' set viewer preferences
   document.ViewerPreferences.CenterWindow = True
   document.ViewerPreferences.DisplayDocTitle = True

   ' hide UI elements in the viewer application
   document.ViewerPreferences.HideMenubar = True
   document.ViewerPreferences.HideToolbar = True
   document.ViewerPreferences.HideWindowUI = True

   ' show pages in two columns
   document.ViewerPreferences.PageLayout = PageLayout.TwoColumnLeft

   ' do not show the thumbnails or the bookmark tree
   document.ViewerPreferences.PageMode = PageMode.None

   ' write the modified document back to disk
   Using outFile As New FileStream("..\..\viewerpreferences.pdf", FileMode.Create, FileAccess.Write)
      document.Write(outFile)
   End Using
End Using