DocumentBuilderInsertStyleSeparator Method

Inserts style separator into the document.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.7.0


public void InsertStyleSeparator()


This method allows to apply different paragraph styles to two different parts of a text line.


Shows how to separate styles from two different paragraphs used in one logical printed paragraph.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Append text in the "Heading 1" style
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
builder.Write("This text is in a Heading style. ");

// Insert a style separator

// The style separator appears in the form of a paragraph break that doesn't start a new line
// So, while this looks like one continuous paragraph with two styles in the output document, 
// it is actually two paragraphs with different styles, but no line break between the first and second paragraph
Assert.AreEqual(2, doc.FirstSection.Body.Paragraphs.Count);

// Append text with another style
Style paraStyle = builder.Document.Styles.Add(StyleType.Paragraph, "MyParaStyle");
paraStyle.Font.Bold = false;
paraStyle.Font.Size = 8;
paraStyle.Font.Name = "Arial";

// Set the style of the current paragraph to our custom style
// This will apply to only the text after the style separator
builder.ParagraphFormat.StyleName = paraStyle.Name;
builder.Write("This text is in a custom style. ");

doc.Save(ArtifactsDir + "DocumentBuilder.InsertStyleSeparator.docx");

See Also