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 zoom_percent property, or the view mode using the view_type 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 characters_per_line property. You can also set the number of lines per page for a Word document – use the lines_per_page 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 msw_version 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 optimize_for 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 initial zoom level of a document when it is opened in Microsoft Word?
    A: Use the ViewOptions class and set its zoom_percent property to the desired percentage (e.g., 50). Then assign the ViewOptions instance to the document’s view_options property before saving.

  2. Q: Which properties control the number of characters per line and lines per page in a document?
    A: The PageSetup class provides characters_per_line and lines_per_page. Set these properties on the document’s page_setup object to define the document grid used by Word, especially for Asian language layouts.

  3. Q: How do I add or change editing languages for a document?
    A: Create a LanguagePreferences object, add the desired language codes (e.g., "ja-JP" for Japanese) to its editing_languages collection, and assign it to the load_options.language_preferences before loading or saving the document.

  4. Q: What is the purpose of the optimize_for method, and when should I use it?
    A: optimize_for configures compatibility options so the document opens without Word’s “Compatibility mode” ribbon for a specific Word version (e.g., CompatibilityOptions.OptimizeFor.WORD_2016). Use it when you need the document to behave like it was created in that version.

  5. Q: How can I ensure the document renders correctly for a specific Microsoft Word version?
    A: Set the LoadOptions.msw_version property to the target Word version (e.g., MsWordVersion.WORD_2016). This makes Aspose.Words emulate the rendering and layout behavior of that Word version during loading.