com.aspose.words

Class ViewOptions

  • java.lang.Object
    • com.aspose.words.ViewOptions
  • All Implemented Interfaces:
    java.lang.Cloneable
    public class ViewOptions 
    extends java.lang.Object

Provides various options that control how a document is shown in Microsoft Word.

Example:

Shows how to set a custom zoom factor, which older versions of Microsoft Word will apply to a document upon loading.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("Hello world!");

doc.getViewOptions().setViewType(ViewType.PAGE_LAYOUT);
doc.getViewOptions().setZoomPercent(50);

Assert.assertEquals(ZoomType.CUSTOM, doc.getViewOptions().getZoomType());
Assert.assertEquals(ZoomType.NONE, doc.getViewOptions().getZoomType());

doc.save(getArtifactsDir() + "ViewOptions.SetZoomPercentage.doc");

Example:

Shows how to set a custom zoom type, which older versions of Microsoft Word will apply to a document upon loading.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("Hello world!");

// Set the "ZoomType" property to "ZoomType.PageWidth" to get Microsoft Word
// to automatically zoom the document to fit the width of the page.
// Set the "ZoomType" property to "ZoomType.FullPage" to get Microsoft Word
// to automatically zoom the document to make the entire first page visible.
// Set the "ZoomType" property to "ZoomType.TextFit" to get Microsoft Word
// to automatically zoom the document to fit the inner text margins of the first page.
doc.getViewOptions().setZoomType(zoomType);

doc.save(getArtifactsDir() + "ViewOptions.SetZoomType.doc");
See Also:
Document, Document.ViewOptions

Property Getters/Setters Summary
booleangetDisplayBackgroundShape()
void
           Controls display of the background shape in print layout view.
booleangetDoNotDisplayPageBoundaries()
void
           Turns off display of the space between the top of the text and the top edge of the page.
booleangetFormsDesign()
void
setFormsDesign(booleanvalue)
           Specifies whether the document is in forms design mode.
intgetViewType()
void
setViewType(intvalue)
           Controls the view mode in Microsoft Word. The value of the property is ViewType integer constant.
intgetZoomPercent()
void
setZoomPercent(intvalue)
           Gets or sets the percentage (between 10 and 500) at which you want to view your document.
intgetZoomType()
void
setZoomType(intvalue)
           Gets or sets a zoom value based on the size of the window. The value of the property is ZoomType integer constant.
 

    • Property Getters/Setters Detail

      • getDisplayBackgroundShape/setDisplayBackgroundShape

        public boolean getDisplayBackgroundShape() / public void setDisplayBackgroundShape(boolean value)
        
        Controls display of the background shape in print layout view.

        Example:

        Shows how to hide/display document background images in view options.
        // Use an HTML string to create a new document with a flat background color.
        final String HTML =
                "<html>\r\n                <body style='background-color: blue'>\r\n                    <p>Hello world!</p>\r\n                </body>\r\n            </html>";
        
        Document doc = new Document(new ByteArrayInputStream(HTML.getBytes()));
        
        // The source for the document has a flat color background,
        // the presence of which will set the "DisplayBackgroundShape" flag to "true".
        Assert.assertTrue(doc.getViewOptions().getDisplayBackgroundShape());
        
        // Keep the "DisplayBackgroundShape" as "true" to get the document to display the background color.
        // This may affect some text colors to improve visibility.
        // Set the "DisplayBackgroundShape" to "false" to not display the background color.
        doc.getViewOptions().setDisplayBackgroundShape(displayBackgroundShape);
        
        doc.save(getArtifactsDir() + "ViewOptions.DisplayBackgroundShape.docx");
      • getDoNotDisplayPageBoundaries/setDoNotDisplayPageBoundaries

        public boolean getDoNotDisplayPageBoundaries() / public void setDoNotDisplayPageBoundaries(boolean value)
        
        Turns off display of the space between the top of the text and the top edge of the page.

        Example:

        Shows how to hide vertical whitespace and headers/footers in view options.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert content that spans across 3 pages.
        builder.writeln("Paragraph 1, Page 1.");
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.writeln("Paragraph 2, Page 2.");
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.writeln("Paragraph 3, Page 3.");
        
        // Insert a header and a footer.
        builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
        builder.writeln("This is the header.");
        builder.moveToHeaderFooter(HeaderFooterType.FOOTER_PRIMARY);
        builder.writeln("This is the footer.");
        
        // This document contains a small amount of content that takes up a few full pages worth of space.
        // Set the "DoNotDisplayPageBoundaries" flag to "true" to get older versions of Microsoft Word to omit headers,
        // footers, and much of the vertical whitespace when displaying our document.
        // Set the "DoNotDisplayPageBoundaries" flag to "false" to get older versions of Microsoft Word
        // to normally display our document.
        doc.getViewOptions().setDoNotDisplayPageBoundaries(doNotDisplayPageBoundaries);
        
        doc.save(getArtifactsDir() + "ViewOptions.DisplayPageBoundaries.doc");
      • getFormsDesign/setFormsDesign

        public boolean getFormsDesign() / public void setFormsDesign(boolean value)
        
        Specifies whether the document is in forms design mode.

        Currently works only for documents in WordML format.

        Example:

        Shows how to enable/disable forms design mode.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.writeln("Hello world!");
        
        // Set the "FormsDesign" property to "false" to keep forms design mode disabled.
        // Set the "FormsDesign" property to "true" to enable forms design mode.
        doc.getViewOptions().setFormsDesign(useFormsDesign);
        
        doc.save(getArtifactsDir() + "ViewOptions.FormsDesign.xml");
      • getViewType/setViewType

        public int getViewType() / public void setViewType(int value)
        
        Controls the view mode in Microsoft Word. The value of the property is ViewType integer constant.

        Although Aspose.Words is able to read and write this option, its usage is application-specific. For example MS Word 2013 does not respect the value of this option.

        Example:

        Shows how to set a custom zoom factor, which older versions of Microsoft Word will apply to a document upon loading.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.writeln("Hello world!");
        
        doc.getViewOptions().setViewType(ViewType.PAGE_LAYOUT);
        doc.getViewOptions().setZoomPercent(50);
        
        Assert.assertEquals(ZoomType.CUSTOM, doc.getViewOptions().getZoomType());
        Assert.assertEquals(ZoomType.NONE, doc.getViewOptions().getZoomType());
        
        doc.save(getArtifactsDir() + "ViewOptions.SetZoomPercentage.doc");
      • getZoomPercent/setZoomPercent

        public int getZoomPercent() / public void setZoomPercent(int value)
        
        Gets or sets the percentage (between 10 and 500) at which you want to view your document.

        If value is 0 then this property uses 100 instead, else if value is less than 10 or greater than 500 this property throws.

        Although Aspose.Words is able to read and write this option, its usage is application-specific. For example MS Word 2013 does not respect the value of this option.

        Example:

        Shows how to set a custom zoom factor, which older versions of Microsoft Word will apply to a document upon loading.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.writeln("Hello world!");
        
        doc.getViewOptions().setViewType(ViewType.PAGE_LAYOUT);
        doc.getViewOptions().setZoomPercent(50);
        
        Assert.assertEquals(ZoomType.CUSTOM, doc.getViewOptions().getZoomType());
        Assert.assertEquals(ZoomType.NONE, doc.getViewOptions().getZoomType());
        
        doc.save(getArtifactsDir() + "ViewOptions.SetZoomPercentage.doc");
      • getZoomType/setZoomType

        public int getZoomType() / public void setZoomType(int value)
        
        Gets or sets a zoom value based on the size of the window. The value of the property is ZoomType integer constant.

        Example:

        Shows how to set a custom zoom factor, which older versions of Microsoft Word will apply to a document upon loading.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.writeln("Hello world!");
        
        doc.getViewOptions().setViewType(ViewType.PAGE_LAYOUT);
        doc.getViewOptions().setZoomPercent(50);
        
        Assert.assertEquals(ZoomType.CUSTOM, doc.getViewOptions().getZoomType());
        Assert.assertEquals(ZoomType.NONE, doc.getViewOptions().getZoomType());
        
        doc.save(getArtifactsDir() + "ViewOptions.SetZoomPercentage.doc");

        Example:

        Shows how to set a custom zoom type, which older versions of Microsoft Word will apply to a document upon loading.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.writeln("Hello world!");
        
        // Set the "ZoomType" property to "ZoomType.PageWidth" to get Microsoft Word
        // to automatically zoom the document to fit the width of the page.
        // Set the "ZoomType" property to "ZoomType.FullPage" to get Microsoft Word
        // to automatically zoom the document to make the entire first page visible.
        // Set the "ZoomType" property to "ZoomType.TextFit" to get Microsoft Word
        // to automatically zoom the document to fit the inner text margins of the first page.
        doc.getViewOptions().setZoomType(zoomType);
        
        doc.save(getArtifactsDir() + "ViewOptions.SetZoomType.doc");