Get and set PDF viewer preferences

The following example shows how you can use GemBox.Pdf to set PdfDocument.ViewerPreferences of an existing PDF document in your VB.NET or C# application.

Upload your file (Drag file here)
using GemBox.Pdf;

class Program
{
    static void Main()
    {
        // If using the Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        using (var document = PdfDocument.Load("%InputFileName%"))
        {
            // Get viewer preferences specifying the way the document should be displayed on the screen.
            var viewerPreferences = document.ViewerPreferences;

            // Modify viewer preferences.
            viewerPreferences.CenterWindow = false;
            viewerPreferences.FitWindow = true;
            viewerPreferences.HideMenubar = true;
            viewerPreferences.HideToolbar = false;
            viewerPreferences.NonFullScreenPageMode = PdfPageMode.FullScreen;
            viewerPreferences.ViewArea = PdfPageBoundaryType.MediaBox;

            document.Save("Viewer Preferences.pdf");
        }
    }
}
Imports GemBox.Pdf

Module Program

    Sub Main()

        ' If using the Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Using document = PdfDocument.Load("%InputFileName%")

            ' Get viewer preferences specifying the way the document should be displayed on the screen.
            Dim ViewerPreferences = document.ViewerPreferences

            ' Modify viewer preferences.
            ViewerPreferences.CenterWindow = False
            ViewerPreferences.FitWindow = True
            ViewerPreferences.HideMenubar = True
            ViewerPreferences.HideToolbar = False
            ViewerPreferences.NonFullScreenPageMode = PdfPageMode.FullScreen
            ViewerPreferences.ViewArea = PdfPageBoundaryType.MediaBox

            document.Save("Viewer Preferences.pdf")
        End Using
    End Sub
End Module
PDF Viewer Preferences created with GemBox.Pdf C#/VB.NET library
Screenshot of PDF Viewer Preferences set with GemBox.Pdf library

See also


Next steps

GemBox.Pdf is a .NET component that enables developers to read, merge and split PDF files or execute low-level object manipulations from .NET applications in a simple and efficient way.

Download Buy