Get and set viewer preferences in C# and VB.NET

With GemBox.Pdf, you can get and set PDF files viewer preferences in your C# or VB.NET application.

The following example shows how you can set PdfDocument.ViewerPreferences of an existing PDF document.

PDF Viewer Preferences created with GemBox.Pdf C#/VB.NET library
Screenshot of PDF Viewer Preferences set with GemBox.Pdf library
Upload your file (Drag file here)
using GemBox.Pdf;

class Program
{
    static void Main()
    {
        // If using 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 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

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.


Like it?

Download Buy

If you want to try the GemBox.Pdf yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.