Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
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.
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:
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:
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:
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:
Document doc = new Document(dataDir + "Document.docx");
// Set Word2016 version for document
doc.getCompatibilityOptions().optimizeFor(MsWordVersion.WORD_2016);
// Save the document.
doc.save(dataDir + "output.docx");
Q: How can I set the zoom level that Word uses when opening a document?
A: Use the ViewOptions class. Create a ViewOptions instance, set its ZoomPercent property (e.g., 50), and assign it to the document via Document.updateViewOptions(viewOptions). The document will open at the specified zoom percentage in supported Word versions.
Q: Which properties control the number of lines per page or characters per line?
A: These are part of the PageSetup class. Use pageSetup.setLinesPerPage(int) to define lines per page and pageSetup.setCharactersPerLine(int) for characters per line. They affect the document grid, which is visible when Asian language support is installed.
Q: How do I specify editing and default languages for a document?
A: Create a LanguagePreferences object, add language IDs with addEditingLanguage(LanguageId) or setDefaultEditingLanguage(LanguageId), and assign it to the document’s LoadOptions via loadOptions.setLanguagePreferences(languagePreferences). This ensures Word displays the document with the correct language settings.
Q: What is the purpose of the OptimizeFor method and when should I use it?
A: OptimizeFor configures the document to target a specific Word version (e.g., MsWordVersion.WORD_2016). It removes compatibility features that would otherwise trigger Word’s “Compatibility mode” ribbon. Use it when you know the target Word version and want the document to behave as a native file for that version.
Q: How can I change the view mode (Print Layout, Web Layout, etc.) of a document programmatically?
A: Set the ViewType property of a ViewOptions instance to one of the ViewType enum values such as ViewType.PRINT_LAYOUT or ViewType.WEB. Assign the configured ViewOptions to the document, and Word will open the file using the specified view mode.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.