insertHtml HTML format

Hi,

I am trying to figure out what kind of HTML works fine when inserted in a document using DocumentBuilder.insertHTML method. For example, if I want to avoid using the
tag as it adds extra lines above and below it, but still want to display a new paragraph, I am trying to use the div or span tag to show the alignment.
Inserting the following does not work or show up alignment correctly in the generated aspose document:
1.
Some Text
2. Some Text
So after lot of trial and error, I found that
Some Text
does the trick for it.
This is just one example.
Can you help with suggesting:

  1. If there is a way to show the
    tag without the extra lines around? Adding a
    tag shows content on the new line if I find a way to display alignment information in the span tag.
  2. Some standard documentation for which type of HTML does the aspose document support so that a lot of trial and error is not required.

Thanks a lot.

Hi there,

Thanks for your inquiry.

*aspose_user2:

  1. If there is a way to show the
    tag without the extra lines around? Adding a
    tag shows content on the new line if I find a way to display alignment information in the span tag.*

It would be great if you please share your input HTML document along with expected output document. We will then provide you more information about your query along with code.

aspose_user2:
2. Some standard documentation for which type of HTML does the aspose document support so that a lot of trial and error is not required.

Upon processing HTML, some features of HTML might be lost. You can find a list of limitations upon HTML exporting/importing here:
https://docs.aspose.com/words/java/load-in-the-html-html-xhtml-mhtml-format/
https://docs.aspose.com/words/java/save-in-the-html-html-xhtml-mhtml-format/

Please note that content inserted by DocumentBuilder.insertHtml** method does not inherit formatting specified in DocumentBuilder options. Whole formatting is taken from HTML snippet. If you insert HTML with no formatting specified, then default formatting is used for inserted content.

In case you are using an older version of Aspose.Words, I would suggest you please upgrade to the latest version (v14.3.0) from here and let us know how it goes on your side. I have used the following code example to test your scenario and have not found the shared issue.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertHtml("Some Text"); 
builder.insertHtml("Some Text");
builder.insertHtml("Some Text"); 
doc.save(MyDir + "OutJ.docx");

Hi Thanks for your reply,
I am using Aspose Words.jdk16 13.2.0.0, I dont think I will be able to upgrade to the latest version of aspose as this is the licensed version bought.
In the example you gave, the div and span tag does not show up correctly for me.

  1. I have added this:
    Review Pending
    Update list
  2. I have added:
    new note shows here
    Also note this change in line
    some text to show after the div element.
    I have attached the expected output.

In the first one, the Review Pending line doesnt show alignment of right.
In the second one, the text “some text to show after the div element” moves onto the next line. Does not continue on the same line as in the attached output document.

As I am adding HTML to generate the aspose document, should I be looking at the HTML Import or Export?

Thanks a lot again.

Hi there,

Thanks for your inquiry. I have tested the scenario using latest version of Aspose.Words for Java 14.3.0 and have not found the shared issue. I have attached the output Docx with this post for your kind reference. Please use the latest version of Aspose.Words for Java 14.3.0.

aspose_user2:
As I am adding HTML to generate the aspose document, should I be looking at the HTML Import or Export?

As you are importing HTML into Aspose.Words DOM, please check the following documentation link.
https://docs.aspose.com/words/java/load-in-the-html-html-xhtml-mhtml-format/

aspose_user2:
2. I have added:
new note shows here

Also note this change in line
some text to show after the div element.

Please note that Aspose.Words mimics the same behaviour as MS Word does. If you create HTML document with this Div tag and open the HTML in MS Word, you will get the same output.

Please let us know if you have any more queries.