DocumentBuilderPushFont Method

Saves current character formatting onto the stack.

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


public void PushFont()


Shows how to use temporarily save and restore character formatting when building a document with DocumentBuilder.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Set up font formatting and write text that goes before the hyperlink
builder.Font.Name = "Arial";
builder.Font.Size = 24;
builder.Font.Bold = true;
builder.Write("To visit Google, hold Ctrl and click ");

// Save the font formatting so we use different formatting for hyperlink and restore old formatting later

// Set new font formatting for the hyperlink and insert the hyperlink
// The "Hyperlink" style is a Microsoft Word built-in style so we don't have to worry to 
// create it, it will be created automatically if it does not yet exist in the document
builder.Font.StyleIdentifier = StyleIdentifier.Hyperlink;
builder.InsertHyperlink("here", "", false);

// Restore the formatting that was before the hyperlink

builder.Write(". We hope you enjoyed the example.");

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

See Also