Work with Options and Appearance of Word Documents

Sometimes you may need to change the appearance of a document, for example, set language preferences or the number of lines per page.Aspose.Words provides the ability to control how the document will be displayed, as well as some additional options. This article describes such possibilities.

Set Document Display Options

You can control how a document will be displayed in Microsoft Word using the ViewOptions class. For example, you can set a document zoom value using the ZoomPercent property, or the view mode using the ViewType property.

The following code example shows how to ensure that a document is displayed at 50% when opened in Microsoft Word:

Set Page Display Options

If you want to set the number of characters per line, use the CharactersPerLine property. You can also set the number of lines per page for a Word document – use the LinesPerPage property to get or set the number of lines per page in the document grid.

The following code example shows how to set the number of characters per line and the number of lines per page for a Microsoft Word document:

Set Language Preferences

Displaying a document in Microsoft Word depends on which languages are set as defaults for this document. If no languages are set in defaults, Microsoft Word takes information from the “Set Office Language Preferences” dialog box, which, for example, can be found under “File → Options → Language” in Microsoft Word 2019.

With Aspose.Words, you can also set up language preferences using the LanguagePreferences class. Also note that for the correct display of your document it is necessary to set the Microsoft Word version that the document loading process should match – this can be done using the MswVersion property.

The following code example shows how to add Japanese to editing languages:

The following code example shows how to set Russian as the default editing language:

Optimize a Document for a Particular Word Version

The OptimizeFor method allows optimizing document content, as well as default Aspose.Words behaviour for a particular version of Microsoft Word. You can use this method to prevent Microsoft Word from displaying the “Compatibility mode” ribbon upon document loading. Note that you may also need to set the Compliance property to Iso29500_2008_Transitional or higher.

The following code example shows how to optimize document content for Microsoft Word 2016:


FAQ

  1. Q: How can I set the zoom level of a Word document when it opens in Microsoft Word?
    A: Use the ViewOptions.ZoomPercent property. Assign the desired percentage (e.g., 50) to document.LayoutOptions.ViewOptions.ZoomPercent before saving the document. Note that some Word versions, such as Word 2013, ignore the stored zoom value and use the last used zoom instead.

  2. Q: How do I change the view mode (Print Layout, Web Layout, etc.) programmatically?
    A: Set the ViewOptions.ViewType property to one of the ViewType enumeration values, for example ViewType.PrintLayout or ViewType.Web. This determines how Word initially displays the document when opened.

  3. Q: How can I specify language preferences to ensure correct display of Asian characters?
    A: Create a LanguagePreferences object, add the required editing languages (e.g., languagePreferences.AddEditingLanguage(LanguageId.Japanese)), and assign it to LoadOptions.LanguagePreferences before loading or to document.LanguagePreferences after creation. This influences spell‑checking, hyphenation, and character rendering.

  4. Q: What is the purpose of the OptimizeFor method and when should I use it?
    A: CompatibilityOptions.OptimizeFor adjusts the document’s internal structures to match a specific Microsoft Word version, preventing the Compatibility Mode ribbon from appearing. Call it with the target WordVersion (e.g., WordVersion.Word2016) and optionally set CompatibilityOptions.Compliance to Iso29500_2008_Transitional or higher for better standards compliance.

  5. Q: My document still shows the Compatibility Mode ribbon after calling OptimizeFor. What else should I check?
    A: Verify that the CompatibilityOptions.Compliance property is set to at least Iso29500_2008_Transitional. Also ensure no older compatibility settings remain in the document (e.g., older CompatibilityOptions values). Re‑saving the document after applying both settings usually resolves the issue.