Set Word View Modes in C#, VB.NET

Users can change Word view mode according to own reading habit. This guide introduces a solution to set Word view modes in C# and VB.NET.

There are several Word View Modes provided with customers, including Print Layout, Web Layout, Full Screen, Draft, Outline and Zoom in/out with specified percentage. The view mode can be selected when opening to make the document to be presented to match readers’ reading habit. This guide focuses on demonstrating how to set Word view mode in C# and VB.NET via Spire.Doc for .NET. The screenshot presents the result after setting Word view mode.

Word Document Properties

Spire.Doc for .NET, specializing in operating Word in .NET, offers a ViewSetup class to enable users to set Word view modes through assigning specified values for its properties. In this example, the Word view modes will be set as Web Layout with zoom out 150 percent. Therefore, the set properties of ViewSetup class include DocumentViewType, ZoomPercent and ZoomType.

DocumentViewTyp: There are five types provided by Spire.Doc for .NET: None, NormalLayout, OutlineLayout, PrintLayout and WebLayout.

ZoomPercent: The default ZoomPercent is 100. User can set other percent according to requirements. In this example, ZoomPercent is set as 150.

ZoomType: There are four zoom types provided by Spire.Doc for .NET: Full Page to automatically recalculate zoom percentage to fit one full page; None to use the explicit zoom percentage; PageWidth to automatically recalculate zoom percentage to fit page width; TextFit to automatically recalculate zoom percentage to fit text. Because the zoom percentage is set as 150, so the ZoomType is set as None in this example.

Download and install Spire.Doc for .NET and follow the code:

[C#]
using Spire.Doc;

namespace WordViewMode
{
    class Program
    {
        static void Main(string[] args)
        {
            Document doc = new Document();
            doc.LoadFromFile(@"E:\Work\Documents\WordDocuments\.NET Framework.docx");

            doc.ViewSetup.DocumentViewType = DocumentViewType.WebLayout;
            doc.ViewSetup.ZoomPercent = 150;
            doc.ViewSetup.ZoomType = ZoomType.None;

            doc.SaveToFile("WordViewMode.docx", FileFormat.Docx2010);
            System.Diagnostics.Process.Start("WordViewMode.docx");
        }
    }
}
[VB.NET]
Imports Spire.Doc

Namespace WordViewMode
    Friend Class Program
        Shared Sub Main(ByVal args() As String)
            Dim doc As New Document()
            doc.LoadFromFile("E:\Work\Documents\WordDocuments\.NET Framework.docx")

            doc.ViewSetup.DocumentViewType = DocumentViewType.WebLayout
            doc.ViewSetup.ZoomPercent = 150
            doc.ViewSetup.ZoomType = ZoomType.None

            doc.SaveToFile("WordViewMode.docx", FileFormat.Docx2010)
            System.Diagnostics.Process.Start("WordViewMode.docx")
        End Sub
    End Class
End Namespace

Spire.Doc, professional Word component, is specially designed for developers to fast generate, write, modify and save Word documents in .NET, Silverlight and WPF with C# and VB.NET. Also, it supports conversion between Word and other popular formats, such as PDF, HTML, Image, Text and so on, in .NET and WPF platform.