DocumentBuilderInsertHorizontalRule Method

Inserts a horizontal rule shape into the document.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.2
Syntax
public Shape InsertHorizontalRule()

Return Value

Type: Shape
The shape that is a horizontal rule.
Examples
Shows how to insert horizontal rule shape in a document and customize the formatting.
// Use a document builder to insert a horizontal rule
DocumentBuilder builder = new DocumentBuilder();
Shape shape = builder.InsertHorizontalRule();

HorizontalRuleFormat horizontalRuleFormat = shape.HorizontalRuleFormat;
horizontalRuleFormat.Alignment = HorizontalRuleAlignment.Center;
horizontalRuleFormat.WidthPercent = 70;
horizontalRuleFormat.Height = 3;
horizontalRuleFormat.Color = Color.Blue;
horizontalRuleFormat.NoShade = true;

MemoryStream stream = new MemoryStream();
builder.Document.Save(stream, SaveFormat.Docx);

// Get the rule from the document's shape collection and verify it
Shape horizontalRule = (Shape)builder.Document.GetChild(NodeType.Shape, 0, true);
Assert.True(horizontalRule.IsHorizontalRule);
Assert.True(horizontalRule.HorizontalRuleFormat.NoShade);
Assert.AreEqual(HorizontalRuleAlignment.Center, horizontalRule.HorizontalRuleFormat.Alignment);
Assert.AreEqual(70, horizontalRule.HorizontalRuleFormat.WidthPercent);
Assert.AreEqual(3, horizontalRule.HorizontalRuleFormat.Height);
Assert.AreEqual(Color.Blue.ToArgb(), horizontalRule.HorizontalRuleFormat.Color.ToArgb());
See Also