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

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

The following example demonstrates how to set viewer preferences of an existing PDF document.

Screenshot
PDF Library for C# / VB.NET Screenshot

See the full code below, use Run Example to execute.

Upload your file(Drag files here)

Download an input file

using System;
using System.Text;
using GemBox.Pdf;
using GemBox.Pdf.Content;

class Sample
{
    [STAThread]
    static void Main(string[] args)
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        PdfDocument document = PdfDocument.Load("LoremIpsum.pdf");

        // Get viewer preferences specifying the way the document should be displayed on the screen.
        PdfViewerPreferences 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");
        document.Close();
    }
}
Imports System.Text
Imports GemBox.Pdf
Imports GemBox.Pdf.Content

Module Samples

    Sub Main()

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

        Dim document As PdfDocument = PdfDocument.Load("LoremIpsum.pdf")

        ' Get viewer preferences specifying the way the document should be displayed on the screen.
        Dim ViewerPreferences As PdfViewerPreferences = 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")
        document.Close()

    End Sub

End Module