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

Free Support Forum - aspose.com

An Exception thrown while saving a pdf into HTML format


I am using Aspose PDF 17.9 to convert PDF files into HTML format
Here is my code for test:

String fileName = "425_.pdf";
Document doc = new Document("custom/input/pdf/" + fileName);
new File("custom/output/pdf/" + fileName + "/").mkdirs();

for (int page = 1; page <= doc.getPages().size(); page++) {
	System.out.println("@@@ converting " + page);
	Document pageDoc = null;
	pageDoc = new Document();

	pageDoc.getPageInfo().setMargin(new MarginInfo(0, 0, 0, 0));

	HtmlSaveOptions htmlSaveOps = new HtmlSaveOptions();
	htmlSaveOps.RasterImagesSavingMode = HtmlSaveOptions.RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground;
	htmlSaveOps.FontSavingMode = HtmlSaveOptions.FontSavingModes.AlwaysSaveAsWOFF;
	htmlSaveOps.PartsEmbeddingMode = HtmlSaveOptions.PartsEmbeddingModes.EmbedAllIntoHtml;
	htmlSaveOps.LettersPositioningMethod = LettersPositioningMethods.UseEmUnitsAndCompensationOfRoundingErrorsInCss;

	final StringBuilder htmlBuffer = new StringBuilder();
	htmlSaveOps.CustomHtmlSavingStrategy = new HtmlSaveOptions.HtmlPageMarkupSavingStrategy() {
		public void invoke(HtmlPageMarkupSavingInfo htmlSavingInfo) {
			try {
				htmlBuffer.append(IOUtils.toString(htmlSavingInfo.ContentStream, "utf8"));
			} catch (Exception e) {
			} finally {
	String outHtmlFile = "SomeUnexistingFile.html";
	pageDoc.save(outHtmlFile, htmlSaveOps);

			new FileOutputStream("custom/output/pdf/" + fileName + "/" + page + ".html"));


The exception will be thrown like this

Caused by: java.lang.IllegalArgumentException: Comparison method violates its general contract!
	at java.util.TimSort.mergeHi(TimSort.java:895)
	at java.util.TimSort.mergeAt(TimSort.java:512)
	at java.util.TimSort.mergeCollapse(TimSort.java:437)
	at java.util.TimSort.sort(TimSort.java:241)
	at java.util.Arrays.sort(Arrays.java:1512)
	at com.aspose.pdf.internal.p776.z1.sort(Unknown Source)
	at com.aspose.pdf.internal.p184.z20.m13(Unknown Source)
	at com.aspose.pdf.internal.p184.z20.m1(Unknown Source)
	at com.aspose.pdf.internal.p184.z3.m1(Unknown Source)
	at com.aspose.pdf.internal.p182.z2.m1(Unknown Source)
	at com.aspose.pdf.internal.p179.z1.m1(Unknown Source)
	at com.aspose.pdf.internal.p179.z1.m3(Unknown Source)
	at com.aspose.pdf.internal.p179.z1.m1(Unknown Source)
	at com.aspose.pdf.internal.p179.z1.m1(Unknown Source)
	at com.aspose.pdf.internal.p179.z1.m1(Unknown Source)
	at com.aspose.pdf.internal.p178.z3.m1(Unknown Source)
	at com.aspose.pdf.internal.p158.z9.m1(Unknown Source)
	at com.aspose.pdf.z93.m1(Unknown Source)
	at com.aspose.pdf.z93.m1(Unknown Source)
	at com.aspose.pdf.ADocument.save(Unknown Source)
	at com.aspose.pdf.Document.save(Unknown Source)

The PDF file:

I also uploaded the file which may cause this issue.
Please check the file and this issue, thank you~



We managed to replicate the said error in our environment. It has been logged under the ticket ID PDFJAVA-37170 in our bug tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates.

Hello, has PDFJAVA-37170 been fixed in the latest Aspose PDF for Java? We are hitting this as well.


Thank you for getting back to us.

We are afraid PDFJAVA-37170 is still unresolved owing to previously logged and critical tickets. However, we have recorded your concerns and will let you know once any update will be available in this regard.