Paragraph Format and direct formatting

@tahir.manzoor, is there an equivalent to builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Normal;
but for the builder.Font.StyleIdentifier style?

I’d like to avoid calling builder.Font.ClearFormatting(); because that may clear more than intended.

Thanks.

@dstj

Please note that formatting is applied on a few different levels. For example, let’s consider formatting of simple text. Text in documents is represented by Run element and a Run can only be a child of a Paragraph. You can apply formatting

  1. to Run nodes by using Character Styles e.g. a Glyph Style .
  2. to the parent of those Run nodes i.e. a Paragraph node ( possibly via paragraph Styles ).
  3. you can also apply direct formatting to Run nodes by using Run attributes ( Font ). In this case the Run will inherit formatting of Paragraph Style, a Glyph Style and then direct formatting.

Could you please ZIP and attach your input and expected output documents here for our reference? We will then provide you more information about your query.

@tahir.manzoor, yes exactly, I understand that. But the DocumentBuilder styling options are “additive”. So let’s say I have this:

builder.Font.Bold = true;
builder.Write("Bold    ");
builder.Font.StyleIdentifier = StyleIdentifier.Emphasis;
builder.Write("This is Bold AND Emphasis     ");
builder.Font.ClearFormatting();
builder.Write("This is back to normal text. I want to only remove Emphasis and keep Bold");

ClearFormatting() is too agressive. That being said, I found my answer:

builder.Font.StyleIdentifier = StyleIdentifier.DefaultParagraphFont;

@dstj

You are facing the expected behavior of Aspose.Words. The Font.ClearFormatting method resets to default font formatting.

It is nice to hear from you that your problem has been solved. Please let us know if you have any more queries.