Keeping CSS properties while inserting HTML

Hi there! Let me just say thank you for your great product :slight_smile:

I need some help since i am desperate.
I´m trying to insert html content in a word document using the DocumentBuilder “insertHtml” method.
My html has the CSS properties in the head of the html, but for some reason the resultant word document won´t apply these CSS rules.
My html is like this:

ol,dl,ul{padding:0 40px}ol ol{list-style:lower-alpha;margin-left:1.25em}ol ol ol{list-style:lower-roman;margin-left:2.5em}ol ol ol ol{list-style:decimal}ol ol ol ol ol{list-style:lower-alpha}ol ol ol ol ol ol{list-style:lower-roman}ul ul ul ul{list-style-type:disc}ul ul ul ul ul{list-style-type:circle}ul ul ul ul ul ul{list-style-type:square}li li{padding-left:.4em}li li li{padding-left:0}
  • test 1
  • test 2
  • test 2 a
  • test 2 a i
  • test 2 a ii
  • test 2 b
  • test 2 c
  • test 2 c i
  • test 3
  • test 3 a
  • test 3 b
  • test 3 b i
  • test 4

  • I have tried the code above in Chrome and other browsers and it´s working.
    I have also tried to insert each style directly in the correspondent html tag and it also works, but this is not good for me since the html im processing is dynamic.

    This is what i´m using to insert the html:
    final DocumentBuilder builder = new DocumentBuilder((Document) e.getMatchNode().getDocument());
    builder.insertHtml(this.html, true);

    Any help will be immensely appreciated. I´m totally desperate.
    Thank you so much for reading.
    Kind regards,
    Nuno Silva.
    Hi Nuno,

    Thanks for your inquiry. We have tested the using latest version of Aspose.Words for Java 17.3.0 with following code example. We have not found the shared issue with output document. Please check the attached output. Please use Aspose.Words for Java 17.3.0.

    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);
    builder.insertHtml("\n" +
    " ol,dl,ul............." +
    " your html " +
    " ", true);
    doc.save(MyDir + "17.3.0.docx");

    If you still face problem, please share following detail here for testing.
    • Your input Word document.
    • Please create a simple Java application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

    As soon as you get these pieces of information ready, we'll start investigation into your issue and provide you more information. Thanks for your cooperation.

    PS: To attach these resources, please zip them and Click 'Reply' button that will bring you to the 'reply page' and there at the bottom you can include any attachments with that post by clicking the 'Add/Update' button.

    Hi!

    Thanks for the quick reply.
    This worked very nicely for me!

    Thank you so much for your time.
    Kind regards,
    Nuno Silva