Import of an HTML document adds SpaceBefore and SpaceAfter to Paragraphs in Tables



Importing the following HTML document and exporting it to DOCX results in additional spacing being added to each of the table cells. The documentation claims that paragraphs import their SpaceBefore and SpaceAfter properties from the margin CSS associated with the paragraph, but I do not believe that there is a margin that affects the table in the attached file. Is there any way to resolve this issue?

Mike (12.6 KB)



Thanks for your inquiry. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-16325. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.



Thanks for your patience. It is to inform you that the issue which you are facing is actually not a bug in Aspose.Words. So, we have closed this issue (WORDSNET-16325) as ‘Not a Bug’.

According to the HTML specification, paragraphs in HTML documents have non-zero default vertical margins. When Aspose.Words imports an HTML document, it applies these default margin values and converts them into paragraph spacing. As a result, the document imported by Aspose.Words looks closer to what is seen in browsers than the document imported by MS Word.

In order to change default vertical margins of paragraphs, please modify the source document in any of the following ways:

  • Remove the <!DOCTYPE> declaration. This will tell readers that the document should be opened in the Quirks mode that has special rules for paragraphs inside table cells.
  • Add an explicit rule to the document CSS in order to override default margin values for paragraphs:
    p { margin: 0 }

We have attached the modified HTML and output DOCX with this post for your kind reference. (23.6 KB)