[]
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.
To get the document properties, for example, compatibility mode and hyphenation options:
Get access to the document compatibility options using Settings.CompatibilityOptions property.
Get the document compatibility mode using CompatibilityMode of the CompatibilityOptions class. This will give you the version of Word document.
Get the maximum number of consecutive lines that can end with hyphens using ConsecutiveHyphensLimit property of the HyphenationOptions class.
Display the compatibility mode version and number of consecutive lines that can end with hyphens on the console.
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);
To set the document properties, for example, compatibility mode and hyphenation options:
Get access to the document compatibility options using Settings.CompatibilityOptions property.
Set the document compatibility mode using CompatibilityMode of the CompatibilityOptions class, which takes the value from the WordVersion enumeration.
Set the automatic hyphenation for the document using AutoHyphenation property of the HyphenationOptions class by providing a Boolean value.
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");
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:
Access the viewing options using Settings.ViewOptions property.
Set the view mode using ViewType property of the ViewOptions class which accepts value from the ViewType enumeration.
Set the zoom value using ZoomType property of the ViewOptions class which accepts value from the ZoomType enumeration.
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.
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");
For more information on how implement document properties using GcWord, see GcWord sample browser.