我一直在努力使用PDFClown突出显示pdf,并且大多数工作正常,但在极少数情况下它会给出例外情况,如下面的stacktrace所示:
Exception in thread "main" java.lang.IllegalArgumentException: Comparison method violates its general contract!
at java.util.TimSort.mergeLo(Unknown Source)
at java.util.TimSort.mergeAt(Unknown Source)
at java.util.TimSort.mergeCollapse(Unknown Source)
at java.util.TimSort.sort(Unknown Source)
at java.util.TimSort.sort(Unknown Source)
at java.util.Arrays.sort(Unknown Source)
at java.util.Collections.sort(Unknown Source)
at org.pdfclown.tools.TextExtractor.sort(TextExtractor.java:633)
at org.pdfclown.tools.TextExtractor.extract(TextExtractor.java:284)
at org.pdfclown.samples.cli.TextHighlightSample.run(TextHighlightSample.java:60)
at com.dhawan.poc.Highlight.main(Highlight.java:9)
我知道如何解决这个问题?
答案 0 :(得分:0)
您使用哪个版本的PDFClown?您的堆栈跟踪与http://svn.code.sf.net/p/clown/code/trunk/java/pdfclown.lib处的当前代码不匹配,而是包含用于排序的以下比较:
public int compare(
ITextString textString1,
ITextString textString2
)
{
Rectangle2D box1 = textString1.getBox();
Rectangle2D box2 = textString2.getBox();
if(isOnTheSameLine(box1,box2))
{
/*
[FIX:55:0.1.3] In order not to violate the transitive condition, equivalence on x-axis
MUST fall back on y-axis comparison.
*/
int xCompare = Double.compare(box1.getX(), box2.getX());
if(xCompare != 0)
return xCompare;
}
return Double.compare(box1.getY(), box2.getY());
}
此修复程序已于2014年5月5日推出。如果您拥有0.1.3之前的PDFClown版本或在该日期之前构建的0.1.3版本,则应更新PDFClown。