public class ViewOptions
extends java.lang.Object
implements java.lang.Cloneable
To learn more, visit the Work with Options and Appearance of Word Documents documentation article.
Examples:
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");
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");
Document,
Document.getViewOptions()| Modifier and Type | Method and Description |
|---|---|
boolean |
getDisplayBackgroundShape()
Controls display of the background shape in print layout view.
|
boolean |
getDoNotDisplayPageBoundaries()
Turns off display of the space between the top of the text and the top edge of the page.
|
boolean |
getFormsDesign()
Specifies whether the document is in forms design mode.
|
int |
getViewType()
Controls the view mode in Microsoft Word.
|
int |
getZoomPercent()
Gets the percentage at which you want to view your document.
|
int |
getZoomType()
Gets a zoom value based on the size of the window.
|
protected java.lang.Object |
memberwiseClone() |
void |
setDisplayBackgroundShape(boolean value)
Controls display of the background shape in print layout view.
|
void |
setDoNotDisplayPageBoundaries(boolean value)
Turns off display of the space between the top of the text and the top edge of the page.
|
void |
setFormsDesign(boolean value)
Specifies whether the document is in forms design mode.
|
void |
setViewType(int value)
Controls the view mode in Microsoft Word.
|
void |
setZoomPercent(int value)
Sets the percentage at which you want to view your document.
|
void |
setZoomType(int value)
Sets a zoom value based on the size of the window.
|
public int getViewType()
Remarks:
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.
Examples:
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");
int value. The returned value is one of ViewType constants.public void setViewType(int value)
Remarks:
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.
Examples:
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");
value - The corresponding int value. The value must be one of ViewType constants.public int getZoomType()
Examples:
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");
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");
ZoomType constants.public void setZoomType(int value)
Examples:
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");
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");
value - A zoom value based on the size of the window. The value must be one of ZoomType constants.public int getZoomPercent()
Remarks:
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.
Examples:
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");
public void setZoomPercent(int value)
Remarks:
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.
Examples:
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");
value - The percentage at which you want to view your document.public boolean getDoNotDisplayPageBoundaries()
Examples:
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");
boolean value.public void setDoNotDisplayPageBoundaries(boolean value)
Examples:
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");
value - The corresponding boolean value.public boolean getDisplayBackgroundShape()
Examples:
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");
boolean value.public void setDisplayBackgroundShape(boolean value)
Examples:
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");
value - The corresponding boolean value.public boolean getFormsDesign()
Remarks:
Currently works only for documents in WordML format.
Examples:
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");
boolean value.public void setFormsDesign(boolean value)
Remarks:
Currently works only for documents in WordML format.
Examples:
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");
value - The corresponding boolean value.protected java.lang.Object memberwiseClone()