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

Free Support Forum - aspose.com

Error converting DOCX to HTML using Aspose.words Java



We use Aspose.words Java to convert docx file to html.

When we try to convert this docx file to html, we were not able to convert and getting an error.
image.png (2.5 KB)

Please suggest ways we can mitigate this and let us know your valuable suggestions to resolve this issue.

Please use the attached docx file.
testFile.docx (48.6 KB)


After an initial test with the licensed latest (21.9) version of Aspose.Words for Java, we were unable to reproduce this problem on our end (see Aspose.Words 21.9 generated output: awjava-21.9.zip (8.0 KB)). So, we suggest you to please upgrade to the latest (21.9) version of Aspose.Words for Java.


We upgraded to Aspose.Words for Java 21.9 and still we are getting the error “addition of a duplicate key to a dictionary” when we call the code below:

final Document document = new Document(file.getInputStream());
//Get page count
int pageCount = document.getPageCount();
// remove paragraphs with zero line spacing
for (Paragraph paragraph : document.getFirstSection().getBody().getParagraphs())
if (paragraph.getParagraphFormat().getLineSpacing() == 0)
final HtmlSaveOptions options = new HtmlSaveOptions(HTML);
document.save(String.valueOf(targetLocation), options);

Please share your valuable suggestions to resolve this issue.

Best Regards


Thanks for providing the code. We have logged this problem in our issue tracking system. The ID of this issue is WORDSNET-22810. We will further look into the details of this problem and will keep you updated here on the status of correction. We apologize for your inconvenience.

1 Like


Regarding WORDSNET-22810, it is to inform you that we have completed the analysis of this issue and found the bug in HTML module of Aspose.Words. The HTML writer uses information from the page layout engine; but, since the code modifies the document, the page layout gets expired. As a workaround, you can update the page layout once again by invoking Document.UpdatePageLayout() method just before saving the document. We will inform you via this thread as soon as this issue will get resolved in future.

The issues you have found earlier (filed as WORDSNET-22810) have been fixed in this Aspose.Words for Java 22.6 update.