FieldXEHasPageRangeBookmarkName Property

Gets a value indicating whether a page range bookmark name is provided through the field's code.

Namespace:  Aspose.Words.Fields
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.8.0

Syntax

public bool HasPageRangeBookmarkName { get; }

Property Value

Type: Boolean

Examples

Shows how to specify a bookmark's spanned pages as a page range for an INDEX field entry.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Create an INDEX field which will display the page locations of XE fields in the document body
FieldIndex index = (FieldIndex)builder.InsertField(FieldType.FieldIndex, true);

index.PageNumberSeparator = ", on page(s) ";
index.PageRangeSeparator = " to ";

Assert.AreEqual(" INDEX  \\e \", on page(s) \" \\g \" to \"", index.GetFieldCode());

// Insert an XE field on page 2
builder.InsertBreak(BreakType.PageBreak);
FieldXE indexEntry = (FieldXE)builder.InsertField(FieldType.FieldIndexEntry, true);
indexEntry.Text = "My entry";

// If we use this attribute to refer to a bookmark,
// this XE field's page number will be substituted by the page range that the referenced bookmark spans 
indexEntry.PageRangeBookmarkName = "MyBookmark";

Assert.AreEqual(" XE  \"My entry\" \\r MyBookmark", indexEntry.GetFieldCode());
Assert.True(indexEntry.HasPageRangeBookmarkName);

// Insert a bookmark that starts on page 3 and ends on page 5
// Since the XE field references this bookmark,
// its location page number will show up in the INDEX field's table as "3 to 5" instead of "2",
// which is its actual page
builder.InsertBreak(BreakType.PageBreak);
builder.StartBookmark("MyBookmark");
builder.Write("Start of MyBookmark");
builder.InsertBreak(BreakType.PageBreak);
builder.InsertBreak(BreakType.PageBreak);
builder.Write("End of MyBookmark");
builder.EndBookmark("MyBookmark");

doc.UpdateFields();
doc.Save(ArtifactsDir + "Field.INDEX.XE.PageRangeBookmark.docx");

See Also