Docx save pdf error : addition of a duplicate key to a dictionary

Document doc = new Document("123.docx");	
doc.save("123.pdf", SaveOptions.createSaveOptions(SaveFormat.PDF));

error : addition of a duplicate key to a dictionary

Aspose.word 25.7
123.docx (550.1 KB)

@dhzhao2016

The error “addition of a duplicate key to a dictionary” typically occurs when there are conflicting entries in the document you are trying to convert. This can happen if there are duplicate styles, bookmarks, or other elements that should be unique.

Cause: The issue arises from duplicate entries in your document, such as styles or bookmarks, which violate the uniqueness requirement.

Solution: Here are some steps you can take to troubleshoot and resolve this issue:

  1. Check for Duplicate Styles: Open your DOCX file in Microsoft Word and check if there are any duplicate styles defined. If you find any, consider renaming or removing them.

  2. Inspect Bookmarks: Ensure that there are no duplicate bookmarks in your document. You can do this by going to the “Insert” tab in Word, selecting “Bookmark,” and reviewing the list.

  3. Simplify the Document: If possible, try simplifying the document by removing complex elements or sections one at a time to identify the source of the issue.

  4. Update Aspose.Words: Ensure you are using the latest version of Aspose.Words, as updates may include fixes for known issues.

  5. Use Try-Catch Block: Implement a try-catch block around your save method to catch and log any exceptions for further analysis.

Here’s a minimal code example to help you implement the try-catch block:

try {
    Document doc = new Document("123.docx");
    doc.save("123.pdf", SaveOptions.createSaveOptions(SaveFormat.PDF));
} catch (Exception e) {
    System.out.println("Error: " + e.getMessage());
}

Next Steps: If the issue persists after following these steps, please share the document with Aspose support for further assistance.

Thank you for your patience, and I hope this resolves your issue!

@dhzhao2016
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-28515

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Last version 25.7

java.lang.IllegalArgumentException: error: addition of a duplicate key to a dictionary

@dhzhao2016 We have managed to reproduce the problem on our side and logged it as WORDSNET-28515.

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