Set Viewer Preference of PDF

Set Viewer Preference of an existing PDF File

ViewerPreference class represents display modes of PDF files; for example, positioning the document window in the center of the screen, hiding viewer application’s menu bar etc.

ChangeViewerPreference method in PdfContentEditor class allows you to change the viewer preference. In order to do that, you need to create an object of PdfContentEditor class and bind the input PDF file using BindPdf method.

Ater that, you can call ChangeViewerPreference method to set any preference. Finally, you have to save the updated PDF file using Save method. The following code snippet shows you how to change viewer preference in an existing PDF file.

For example, we specify the parameter CenterWindow with which we center the window, after remove the top toolbar with HideMenubar and with PageModeUseNone open full-screen mode.

 public static void SetViewerPreference()
        {
            var document = new Document(_dataDir + "Sample.pdf");
            PdfContentEditor editor = new PdfContentEditor(document);

            // Change Viewer Preferences
            editor.ChangeViewerPreference(ViewerPreference.CenterWindow);
            editor.ChangeViewerPreference(ViewerPreference.HideMenubar);
            editor.ChangeViewerPreference(ViewerPreference.PageModeFullScreen);
            // Saves the result PDF to file
            editor.Save(_dataDir + "PdfContentEditorDemo_SetViewerPreference.pdf");
            GetViewerPreference();
        }