DocumentBuilder.insertHTML() with text alignment


I’m currently doing something similar to this (below is a much simplified version):

DocumentBuilder builder = new DocumentBuilder(new Document());
builder.insertHTML("<div style=\"text-align:center;\">Centred</div>");

However, when the document is opened in Word the text is not centred. Changing the
tags to
tags does work however. Unfortunately, the HTML we’re writing out comes from a 3rd party and is outwith our control.

Can I check a few things:

  1. is this a known defect?
  2. are there any known workarounds (other than modifying the HTML?)
  3. if this was raised as a bug could someone provide an estimate of when it would be resolved?


Hello Alasdair!
Thank you for reporting this.
The issue you have found is known. Reference number is #7234. We’ll notify you when it is fixed. Hopefully it will occur by the end of 2009. That’s difficult to categorize whether something is bug or a new feature. Now we are refactoring the HTML import module so after the refactoring many such issues will be fixed and some new features are supported. In any case new implementation will be more regular and potentially less bug-capacious.
Current limitation is that attributes of paragraph style are recognized and applied if only specified on
nodes. Character style attributes are taken from style. For instance, font color should be on and won’t be taken from any others. This implementation was initially enough to make a roundtrip of the export from Aspose.Words and Microsoft Word. We are going to eliminate the described restriction.
You are asking about workarounds. It’s not so easy. You can try preprocessing HTML with regular expressions or some parser. We have good experience with HTML Agility Pack. The idea is doing programmatically the same as you tried by hand: put text-align to the style attribute of all
nodes within the

Hi Kelpus,

thanks for the reply.

I appreciate this may is more missing functionality than a defect. We’d still be keen to know when this issue is resolved - look forward to hearing from you later in the year.

Look as if we’ll have to go down the path of modifying the HTML before writing it out,


The issues you have found earlier (filed as WORDSNET-2021) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.