PDF Viewer Preferences

Manipulate PDF
11/2/2011

Downloads

[Visual Studio 2010 Sample Project.zip]: /support/articles/145/Visual Studio 2010 Sample Project.zip "Visual Studio 2010 Sample Project.zip" The following code sample shows how to set the viewer preferences of a PDF document.

using (FileStream inFile = new FileStream(@"..\..\..\inputDocuments\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("..\..\..\inputDocuments\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