Documents for Word .NET Edition
Features / Document / Document Properties
In This Topic
    Document Properties
    In This Topic

    Apart from content, a Word file holds some additional information in the form of document properties. These properties define various attributes of document as a whole.

    GcWord provides following document properties through the GcWordDocument class:

    Body
    GcWord allows you to access the body of the document using the Body property, which contains the text that excludes headers, footers, footnotes, text boxes, etc.
    List Templates
    GcWord provides the ListTemplates property to get a collection of list templates in the document.
    Document Styles
    GcWord allows you to access the collection of styles defined in the document using the Styles property.
    Theme
    GcWord provides the Theme property to get a theme that holds all the different formatting options available to a document through the theme.
    Settings
    GcWord provides the Settings property which gives you options to control various settings of a Word document, such as:
    • Compatibility options: These options influence how the document content appears and are handled using the CompatibilityOptions class which can be accessed using CompatibilityOptions property of the Settings class.
    • View Options: These options in Word documents lets you control the view and layout of a document. They are handled through the ViewOptions class which can be accessed using ViewOptions property of the Settings class.
    • Hyphenation options: These options are useful to render text in different marginal or justified settings by breaking words in between the lines to bring more consistency in text. The options are handled using the HyphenationOptions class which can be accessed using HyphenationOptions property of the Settings class.

    Hyphenated text in a Word document

    Get Document Properties

    To get the document properties, for example, compatibility mode and hyphenation options:

    1. Get access to the document compatibility options using Settings.CompatibilityOptions property.
    2. Get the document compatibility mode using CompatibilityMode of the CompatibilityOptions class. This will give you the version of Word document.
    3. Get the maximum number of consecutive lines that can end with hyphens using ConsecutiveHyphensLimit property of the HyphenationOptions class.
    4. Display the compatibility mode version and number of consecutive lines that can end with hyphens on the console.
      C#
      Copy Code
      doc.Load("SampleDoc.docx");
      
      //get document compatibility mode
      WordVersion version = doc.Settings.CompatibilityOptions.CompatibiltyMode;
      
      //Get the maximum number of consecutive lines that can end with hyphens
      ushort limit = doc.Settings.HyphenationOptions.ConsecutiveHyphensLimit;
                  
      //Display the compatibility mode version on the console
      Console.WriteLine("\n WordVersion: " + version);
      
      //Display the maximum number of consecutive lines that can end with hyphens
      Console.WriteLine("\n consecutive lines ending with hyphens: " + limit);
    Back to Top

    Set Document Properties

    To set the document properties, for example, compatibility mode and hyphenation options:

    1. Get access to the document compatibility options using Settings.CompatibilityOptions property.
    2. Set the document compatibility mode using CompatibilityMode of the CompatibilityOptions class, which takes the value from the WordVersion enumeration.
    3. Set the automatic hyphenation for the document using AutoHyphenation property of the HyphenationOptions class by providing a Boolean value.     
      C#
      Copy Code
      doc.Load("SampleDoc.docx");
      
      //set document compatibility mode
      doc.Settings.CompatibilityOptions.CompatibiltyMode = WordVersion.Word2007;
      
      //Enable automatic hyphenation for the document
      doc.Settings.HyphenationOptions.AutoHyphenation = true;
      
      //Save the modifed Word file
      doc.Save("SetDocProperties.docx");
    Back to Top

    Set View Options

    GcWord provides various options to control how a document is displayed in an application through the ViewOptions class, which can be accessed using the ViewType property. It helps you display the page in different view modes such as master document view, draft view, outline view, print view and webpage view. GcWord also lets you set the zoom levels using the ZoomType property of the ViewOptions class. The different zoom modes available are BestFit, FullPage, TextFit and None. In addition, the ViewOptions class lets you specify the zoom percentage using the Zoom property.

    To set various viewing options, for example, view type, the zoom percentage and zoom type:

    1. Access the viewing options using Settings.ViewOptions property.
    2. Set the view mode using ViewType property of the ViewOptions class which accepts value from the ViewType enumeration.
    3. Set the zoom value using ZoomType property of the ViewOptions class which accepts value from the ZoomType enumeration.
    4. Set the zoom percentage using Zoom property of the ViewOptions class.
    Note: Microsoft Word ignores these properties set through the ViewOptions class while displaying a document as it reads the properties directly from the Windows registry.
    C#
    Copy Code
    doc.Load("SampleDoc.docx");
    
    //set view type
    doc.Settings.ViewOptions.ViewType = ViewType.Print;
    
    //set zoom type
    doc.Settings.ViewOptions.ZoomType = ZoomType.Fullpage;
    
    //set zoom percentage
    doc.Settings.ViewOptions.Zoom = 150;
    
    doc.Save("ViewOptionsAdded.docx");

    Back to Top

    For more information on how implement document properties using GcWord, see GcWord sample browser.