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

Free Support Forum - aspose.com

Facing problem with "insertHtml" method

Whenever I am trying to use, "insertHtml" method with any kind of list, I am unable to get the desired result.

For eg. if I am using:

  • Cow
  • Cat
the result should be: .Cow .Cat but the above rendition is giving the result: Cow Cat Please let me know how to handle this.

Waiting for reply

Regards


Hi

Thanks for your request. Please try using the following code to create list:

// Open document.

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

builder.insertHtml("

  1. Items One
    1. Item One
    2. Item Two
    3. Item Three
    4. Items Two
      1. Item One
      2. Item Two
      3. Item Three
      4. ");

        doc.save("C:\\Temp\\out.doc");

        Maybe in your case, you can build lists programmatically. Please see the following code for example:

        Document doc = new Document();

        // Create a list based on one of the Microsoft Word list templates.

        List list = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);

        // Completely customize one list level.

        ListLevel level1 = list.getListLevels().get(0);

        level1.setNumberStyle(NumberStyle.ARABIC);

        level1.setNumberFormat("\u0000)");

        // Completely customize yet another list level.

        ListLevel level2 = list.getListLevels().get(1);

        level2.setNumberStyle(NumberStyle.LOWERCASE_LETTER);

        level2.setNumberFormat("\u0001)");

        level2.setRestartAfterLevel(0);

        // Now add some text that uses the list that we created.

        // It does not matter when to customize the list - before or after adding the paragraphs.

        DocumentBuilder builder = new DocumentBuilder(doc);

        builder.getListFormat().setList(list);

        builder.writeln("Items One");

        builder.getListFormat().listIndent();

        builder.writeln("Item One");

        builder.writeln("Item Two");

        builder.writeln("Item Three");

        builder.getListFormat().listOutdent();

        builder.writeln("Items Two");

        builder.getListFormat().listIndent();

        builder.writeln("Item One");

        builder.writeln("Item Two");

        builder.writeln("Item Three");

        builder.getListFormat().removeNumbers();

        // Save ouput document.

        doc.save("C:\\Temp\\out.doc");

        Hope this helps.

        Best regards.

        Thanks for the reply.

        But can you please help me in rendering this sort of bullet list (as mentioned below) in the doc file generated using insertHtml method:
        (The below mentioned code is from an html file, I am reading the html file line by line and then by using document builder, writing this line in the doc):


        • Bullet Design Damaged

        • Right Panel Image
          Some rights reserved.





        • Damaged Circled Bullet



        1. Bullet Number



        2. <td
          class=""
          >
           
          <td
          class=""
          >


          <td
          class=“mceVisualAid”
          >
           
          <td
          class=""
          >







        Please help me with this problem.

        Also please let me know if there is any method available in aspose words, where a programmer can directly read a html file and convert it into a doc file with absolutely the same styling as present in the html file.

        Waiting for reply.

        Regards

        Hi

        Thanks for your request. Most likely, you are using old version Aspose.Words and that is why the problem occurs. The fact that older versions of Aspose.Words do not properly import list items with nested

        or

        tags. This problem was fixed few releases ago.

        I checked your HTML with the latest version and as I can see it is imported properly. So, please try using the latest version of Aspose.Words for java. You can download it from here:

        http://www.aspose.com/community/files/72/java-components/aspose.words-for-java/default.aspx

        Best regards,

        Hi

        Thanks for your request. As I can see, the image is handled perfectly. Please see the attached output document produced on my side. The only change I made in your HTML – I changed the image url.

        Regarding tables, In Ms Word documents, you cannot use table as a part of a list item. List items in MS Word document is a simple paragraph. Paragraph and Table nodes are on the same level in the document hierarchy. So table cannot be a child of a paragraph. That is why table is inserted after a bullet.

        Best regards,

        Thank you for the reply.

        Its fine if table is inserted after the bullet, bullet how table is getting displayed is the main problem.


        For this table in the html, the resultant table in the doc formed is as shown below:


        Please help me in rendering the image in a manner which is even visible in the document properly.

        Waiting for reply.

        Regards

        Hi Ankur,

        Thank you for additional information. But it is difficult to tell you what the problem is without looking at your source HTML. Could you please attach it here for testing? I will check it and provide you more information.

        Best regards,

        Thank you for the reply.

        I am attaching with this message both the html file and the generated document file.

        Hopefully, you will resolve the issue and let me know.

        Also please let me know whether Aspose.words provide support for openOffice or not.

        Waiting for reply.

        Regards

        Hi Ankur,

        Thank you for additional information. It seems I understood what the problem is. The table does not look as expected on your side because you are opening the DOC file in OpenOffice. And OpenOffice does not like the table. If you open the file using MS Word, the table will look as expected.

        Sure, Aspose.Words supports OpenOffice file formats. So you can easily save your HTML as ODT, in this case, the table looks as expected in OpenOffice.

        Best regards,