We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Bold- Italics etc in DocumentBuilder

Hi! Toggling the italics-property in DocumentBuilder results in subsequent text that should be italic to be non-italic. I’ve verified this ni the latest version av Aspose Words .Net 14.5.

Consider the following code:

var aDoc = SetupDoc(); // incl licensing
aDoc.Sections.Clear();
DocumentBuilder builder = new DocumentBuilder(aDoc);
builder.ParagraphFormat.ClearFormatting();
builder.ParagraphFormat.StyleName = “Normal”;
builder.Write(“A line of text, w/ one word in: “);
builder.Italic = true;
builder.Write(“italics”);
builder.Italic = false;
builder.Writeln(” in it.”);
builder.ParagraphFormat.ClearFormatting();
builder.ParagraphFormat.StyleName = “Heading 4”;
builder.Writeln(“Headline Heading 4 --> incl. italics - but becomes non-italics”);
builder.ParagraphFormat.ClearFormatting();
builder.ParagraphFormat.StyleName = “Normal kursiv”;
builder.Writeln(“Regular text that uses style Normal italics and turns out to not use italics…”);

That one word in italics will in fact be italics, but that Heading 4 that should also appear in italics appears as regular text. Removing that word italics and the properties will result in the proper behaviour for Heading 4.

Replacing the builder.Italic = true and such with:

builder.InsertHtml(“italics”);

Will solve it, but I would rather prefer to use the properties on documentbuilder…

Rgds, Patrik

PS. Attached is a PDF with the code as well as the output rendered from Word 2013.


Hi Christer,


Thanks for your inquiry. You need to reset font formatting to the defaults. Please see following code for example.

Document doc = new
Document(MyDir + @“in.docx”);

doc.Sections.Clear();

DocumentBuilder builder = new DocumentBuilder(doc);

builder.ParagraphFormat.ClearFormatting();

builder.ParagraphFormat.StyleName = "Normal";

builder.Write("A line of text, w/ one word in: ");

builder.Italic = true;

builder.Write("italics");

builder.Italic = false;

builder.Writeln(" in it.");

builder.Font.ClearFormatting();

builder.ParagraphFormat.ClearFormatting();

builder.ParagraphFormat.StyleName = "Heading 4";

builder.Writeln("Headline Heading 4 --> incl. italics - but becomes non-italics");

builder.ParagraphFormat.ClearFormatting();

builder.ParagraphFormat.StyleName = "Normal kursiv";

builder.Writeln("Regular text that uses style Normal italics and turns out to not use italics...");

doc.Save(MyDir + @“out.docx”);


I hope, this helps.

Best regards,