public class ViewOptions
Example:
Shows how to make sure the document is displayed at 50% zoom when opened in Microsoft Word.Document doc = new Document(getMyDir() + "Document.docx"); // We can set the zoom factor to a percentage doc.getViewOptions().setViewType(ViewType.PAGE_LAYOUT); doc.getViewOptions().setZoomPercent(50); // Or we can set the ZoomType to a different value to avoid using percentages Assert.assertEquals(ZoomType.NONE, doc.getViewOptions().getZoomType()); doc.save(getArtifactsDir() + "ViewOptions.SetZoom.docx");
Property Getters/Setters Summary | ||
---|---|---|
boolean | getDisplayBackgroundShape() | |
void | setDisplayBackgroundShape(booleanvalue) | |
Controls display of the background shape in print layout view. | ||
boolean | getDoNotDisplayPageBoundaries() | |
void | setDoNotDisplayPageBoundaries(booleanvalue) | |
Turns off display of the space between the top of the text and the top edge of the page. | ||
boolean | getFormsDesign() | |
void | setFormsDesign(booleanvalue) | |
Specifies whether the document is in forms design mode. | ||
int | getViewType() | |
void | setViewType(intvalue) | |
Controls the view mode in Microsoft Word. The value of the property is ViewType integer constant. | ||
int | getZoomPercent() | |
void | setZoomPercent(intvalue) | |
Gets or sets the percentage (between 10 and 500) at which you want to view your document. | ||
int | getZoomType() | |
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. |
public boolean getDisplayBackgroundShape() / public void setDisplayBackgroundShape(boolean value)
Example:
Shows how to hide/display document background images in view options.// Create a new document from an html string 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 turn on the DisplayBackgroundShape flag // We can disable it like this doc.getViewOptions().setDisplayBackgroundShape(false); doc.save(getArtifactsDir() + "ViewOptions.DisplayBackgroundShape.docx");
public boolean getDoNotDisplayPageBoundaries() / public void setDoNotDisplayPageBoundaries(boolean value)
Example:
Shows how to hide vertical whitespace and headers/footers in view options.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Insert content spanning 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("Header"); builder.moveToHeaderFooter(HeaderFooterType.FOOTER_PRIMARY); builder.writeln("Footer"); // In this case we have a lot of space taken up by quite a little amount of content // In older versions of Microsoft Word, we can hide headers/footers and compact vertical whitespace of pages // to give the document's main body content some flow by setting this flag doc.getViewOptions().setDoNotDisplayPageBoundaries(true); doc.save(getArtifactsDir() + "ViewOptions.DisplayPageBoundaries.docx");
public boolean getFormsDesign() / public void setFormsDesign(boolean value)
Currently works only for documents in WordML format.
Example:
Shows how to save to a .wml document while applying save options.Document doc = new Document(getMyDir() + "Document.docx"); WordML2003SaveOptions options = new WordML2003SaveOptions(); { options.setSaveFormat(SaveFormat.WORD_ML); options.setMemoryOptimization(true); options.setPrettyFormat(true); } // Enables forms design mode in WordML documents doc.getViewOptions().setFormsDesign(useFormsDesign); doc.save(getArtifactsDir() + "ViewOptions.FormsDesign.xml", options);
public int getViewType() / public void setViewType(int value)
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 make sure the document is displayed at 50% zoom when opened in Microsoft Word.Document doc = new Document(getMyDir() + "Document.docx"); // We can set the zoom factor to a percentage doc.getViewOptions().setViewType(ViewType.PAGE_LAYOUT); doc.getViewOptions().setZoomPercent(50); // Or we can set the ZoomType to a different value to avoid using percentages Assert.assertEquals(ZoomType.NONE, doc.getViewOptions().getZoomType()); doc.save(getArtifactsDir() + "ViewOptions.SetZoom.docx");
public int getZoomPercent() / public void setZoomPercent(int value)
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 make sure the document is displayed at 50% zoom when opened in Microsoft Word.Document doc = new Document(getMyDir() + "Document.docx"); // We can set the zoom factor to a percentage doc.getViewOptions().setViewType(ViewType.PAGE_LAYOUT); doc.getViewOptions().setZoomPercent(50); // Or we can set the ZoomType to a different value to avoid using percentages Assert.assertEquals(ZoomType.NONE, doc.getViewOptions().getZoomType()); doc.save(getArtifactsDir() + "ViewOptions.SetZoom.docx");
public int getZoomType() / public void setZoomType(int value)
Example:
Shows how to make sure the document is displayed at 50% zoom when opened in Microsoft Word.Document doc = new Document(getMyDir() + "Document.docx"); // We can set the zoom factor to a percentage doc.getViewOptions().setViewType(ViewType.PAGE_LAYOUT); doc.getViewOptions().setZoomPercent(50); // Or we can set the ZoomType to a different value to avoid using percentages Assert.assertEquals(ZoomType.NONE, doc.getViewOptions().getZoomType()); doc.save(getArtifactsDir() + "ViewOptions.SetZoom.docx");