com.aspose.words
Class OutlineOptions

java.lang.Object
    extended by com.aspose.words.OutlineOptions

public class OutlineOptions 
extends java.lang.Object

Allows to specify outline options.

Example:

Shows how bookmarks in headers/footers are exported to pdf.
Document doc = new Document(getMyDir() + "Bookmarks in headers and footers.docx");

// You can specify how bookmarks in headers/footers are exported
// There is a several options for this:
// "None" - Bookmarks in headers/footers are not exported
// "First" - Only bookmark in first header/footer of the section is exported
// "All" - Bookmarks in all headers/footers are exported
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.setHeaderFooterBookmarksExportMode(headerFooterBookmarksExportMode);
saveOptions.getOutlineOptions().setDefaultBookmarksOutlineLevel(1);

doc.save(getArtifactsDir() + "PdfSaveOption.HeaderFooterBookmarksExportMode.pdf", saveOptions);

Constructor Summary
OutlineOptions()
          
 
Property Getters/Setters Summary
BookmarksOutlineLevelCollectiongetBookmarksOutlineLevels()
           Allows to specify individual bookmarks outline level.
booleangetCreateMissingOutlineLevels()
voidsetCreateMissingOutlineLevels(boolean value)
          

Gets or sets a value determining whether or not to create missing outline levels when the document is exported.

Default value for this property is false.

booleangetCreateOutlinesForHeadingsInTables()
voidsetCreateOutlinesForHeadingsInTables(boolean value)
           Specifies whether or not to create outlines for headings (paragraphs formatted with the Heading styles) inside tables.
intgetDefaultBookmarksOutlineLevel()
voidsetDefaultBookmarksOutlineLevel(int value)
           Specifies the default level in the document outline at which to display Word bookmarks.
intgetExpandedOutlineLevels()
voidsetExpandedOutlineLevels(int value)
           Specifies how many levels in the document outline to show expanded when the file is viewed.
intgetHeadingsOutlineLevels()
voidsetHeadingsOutlineLevels(int value)
           Specifies how many levels of headings (paragraphs formatted with the Heading styles) to include in the document outline.
 

Constructor Detail

OutlineOptions

public OutlineOptions()

Property Getters/Setters Detail

getBookmarksOutlineLevels

public BookmarksOutlineLevelCollection getBookmarksOutlineLevels()
Allows to specify individual bookmarks outline level.

If bookmark level is not specified in this collection then DefaultBookmarksOutlineLevel value is used.

Example:

Shows how to set outline levels for bookmarks.
// Open a blank document, create a DocumentBuilder, and use the builder to add some text wrapped inside bookmarks
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Note that whitespaces in bookmark names will be converted into underscores when saved to Microsoft Word formats
// such as .doc and .docx, but will be preserved in other formats like .pdf or .xps
builder.startBookmark("Bookmark 1");
builder.writeln("Text inside Bookmark 1.");

builder.startBookmark("Bookmark 2");
builder.writeln("Text inside Bookmark 1 and 2.");
builder.endBookmark("Bookmark 2");

builder.writeln("Text inside Bookmark 1.");
builder.endBookmark("Bookmark 1");

builder.startBookmark("Bookmark 3");
builder.writeln("Text inside Bookmark 3.");
builder.endBookmark("Bookmark 3");

// We can specify outline levels for our bookmarks so that they show up in the table of contents and are indented by an amount
// of space proportional to the indent level in a SaveOptions object
// Some pdf/xps readers such as Google Chrome also allow the collapsing of all higher level bookmarks by adjacent lower level bookmarks
// This feature applies to .pdf or .xps file formats, so only their respective SaveOptions subclasses will support it
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
BookmarksOutlineLevelCollection outlineLevels = pdfSaveOptions.getOutlineOptions().getBookmarksOutlineLevels();

outlineLevels.add("Bookmark 1", 1);
outlineLevels.add("Bookmark 2", 2);
outlineLevels.add("Bookmark 3", 3);

Assert.assertEquals(outlineLevels.getCount(), 3);
Assert.assertTrue(outlineLevels.contains("Bookmark 1"));
Assert.assertEquals(outlineLevels.get(0), 1);
Assert.assertEquals(outlineLevels.get("Bookmark 2"), 2);
Assert.assertEquals(outlineLevels.indexOfKey("Bookmark 3"), 2);

// We can remove two elements so that only the outline level designation for "Bookmark 1" is left
outlineLevels.removeAt(2);
outlineLevels.remove("Bookmark 2");

// We have 9 bookmark levels to work with, and bookmark levels are also sorted in ascending order,
// and get numbered in succession along that order
// Practically this means that our three levels "1, 5, 9", will be seen as "1, 2, 3" in the output
outlineLevels.add("Bookmark 2", 5);
outlineLevels.add("Bookmark 3", 9);

// Save the document as a .pdf and find links to the bookmarks and their outline levels
doc.save(getArtifactsDir() + "BookmarksOutlineLevelCollection.BookmarkLevels.pdf", pdfSaveOptions);

// We can empty this dictionary to remove the contents table
outlineLevels.clear();

getCreateMissingOutlineLevels/setCreateMissingOutlineLevels

public boolean getCreateMissingOutlineLevels() / public void setCreateMissingOutlineLevels(boolean value)

Gets or sets a value determining whether or not to create missing outline levels when the document is exported.

Default value for this property is false.

Example:

Shows how to create PDF document outline entries for headings.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Creating TOC entries
builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1);
Assert.assertTrue(builder.getParagraphFormat().isHeading());

builder.writeln("Heading 1");

builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_4);

builder.writeln("Heading 1.1.1.1");
builder.writeln("Heading 1.1.1.2");

builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_9);

builder.writeln("Heading 1.1.1.1.1.1.1.1.1");
builder.writeln("Heading 1.1.1.1.1.1.1.1.2");

// Create "PdfSaveOptions" with some mandatory parameters
// "HeadingsOutlineLevels" specifies how many levels of headings to include in the document outline
// "CreateMissingOutlineLevels" determining whether or not to create missing heading levels
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.getOutlineOptions().setHeadingsOutlineLevels(9);
pdfSaveOptions.getOutlineOptions().setCreateMissingOutlineLevels(true);
pdfSaveOptions.setSaveFormat(SaveFormat.PDF);

doc.save(getArtifactsDir() + "PdfSaveOptions.CreateMissingOutlineLevels.pdf", pdfSaveOptions);

getCreateOutlinesForHeadingsInTables/setCreateOutlinesForHeadingsInTables

public boolean getCreateOutlinesForHeadingsInTables() / public void setCreateOutlinesForHeadingsInTables(boolean value)
Specifies whether or not to create outlines for headings (paragraphs formatted with the Heading styles) inside tables.

Default value is false.

Example:

Shows how to create PDF document outline entries for headings inside tables.
// Create a blank document and insert a table with a heading-style text inside it
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.startTable();
builder.insertCell();
builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1);
builder.write("Heading 1");
builder.endRow();
builder.insertCell();
builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.NORMAL);
builder.write("Cell 1");
builder.endTable();

// Create a PdfSaveOptions object that, when saving to .pdf with it, creates entries in the document outline for all headings levels 1-9,
// and make sure headings inside tables are registered by the outline also
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.getOutlineOptions().setHeadingsOutlineLevels(9);
pdfSaveOptions.getOutlineOptions().setCreateOutlinesForHeadingsInTables(true);

doc.save(getArtifactsDir() + "PdfSaveOptions.TableHeadingOutlines.pdf", pdfSaveOptions);

getDefaultBookmarksOutlineLevel/setDefaultBookmarksOutlineLevel

public int getDefaultBookmarksOutlineLevel() / public void setDefaultBookmarksOutlineLevel(int value)
Specifies the default level in the document outline at which to display Word bookmarks.

Individual bookmarks level could be specified using BookmarksOutlineLevels property.

Specify 0 and Word bookmarks will not be displayed in the document outline. Specify 1 and Word bookmarks will be displayed in the document outline at level 1; 2 for level 2 and so on.

Default is 0. Valid range is 0 to 9.

Example:

Shows how bookmarks in headers/footers are exported to pdf.
Document doc = new Document(getMyDir() + "Bookmarks in headers and footers.docx");

// You can specify how bookmarks in headers/footers are exported
// There is a several options for this:
// "None" - Bookmarks in headers/footers are not exported
// "First" - Only bookmark in first header/footer of the section is exported
// "All" - Bookmarks in all headers/footers are exported
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.setHeaderFooterBookmarksExportMode(headerFooterBookmarksExportMode);
saveOptions.getOutlineOptions().setDefaultBookmarksOutlineLevel(1);

doc.save(getArtifactsDir() + "PdfSaveOption.HeaderFooterBookmarksExportMode.pdf", saveOptions);

getExpandedOutlineLevels/setExpandedOutlineLevels

public int getExpandedOutlineLevels() / public void setExpandedOutlineLevels(int value)
Specifies how many levels in the document outline to show expanded when the file is viewed.

Note that this options will not work when saving to XPS.

Specify 0 and the document outline will be collapsed; specify 1 and the first level items in the outline will be expanded and so on.

Default is 0. Valid range is 0 to 9.

Example:

Converts a whole document to PDF with three levels in the document outline.
Document doc = new Document(getMyDir() + "Rendering.docx");

PdfSaveOptions options = new PdfSaveOptions();
options.getOutlineOptions().setHeadingsOutlineLevels(3);
options.getOutlineOptions().setExpandedOutlineLevels(1);

doc.save(getArtifactsDir() + "Rendering.SaveToPdfWithOutline.pdf", options);

getHeadingsOutlineLevels/setHeadingsOutlineLevels

public int getHeadingsOutlineLevels() / public void setHeadingsOutlineLevels(int value)
Specifies how many levels of headings (paragraphs formatted with the Heading styles) to include in the document outline.

Specify 0 for no headings in the outline; specify 1 for one level of headings in the outline and so on.

Default is 0. Valid range is 0 to 9.

Example:

Converts a whole document to PDF with three levels in the document outline.
Document doc = new Document(getMyDir() + "Rendering.docx");

PdfSaveOptions options = new PdfSaveOptions();
options.getOutlineOptions().setHeadingsOutlineLevels(3);
options.getOutlineOptions().setExpandedOutlineLevels(1);

doc.save(getArtifactsDir() + "Rendering.SaveToPdfWithOutline.pdf", options);

See Also:
          Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
          Aspose.Words Support Forum - our preferred method of support.