Skip to content

Commit 8941ee3

Browse files
Make CompareTool compare page dictionaries as usual dictionaries if both cmp and out page dicts are not in the doc's page trees
DEVSIX-2137
1 parent 680a4df commit 8941ee3

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

kernel/src/main/java/com/itextpdf/kernel/utils/CompareTool.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,12 +1411,19 @@ private boolean compareObjects(PdfObject outObj, PdfObject cmpObj, ObjectPath cu
14111411
outPagesRef.add(outRefKey.getDocument().getPage(i).getPdfObject().getIndirectReference());
14121412
}
14131413
}
1414-
if (cmpPagesRef.contains(cmpRefKey) && cmpPagesRef.indexOf(cmpRefKey) == outPagesRef.indexOf(outRefKey))
1415-
return true;
1416-
if (compareResult != null && currentPath != null)
1417-
compareResult.addError(currentPath, MessageFormatUtil.format("The dictionaries refer to different pages. Expected page number: {0}. Found: {1}",
1418-
cmpPagesRef.indexOf(cmpRefKey) + 1, outPagesRef.indexOf(outRefKey)) + 1);
1419-
return false;
1414+
1415+
// If at least on of the page dictionaries is in the document's page tree, we don't proceed with deep comparison,
1416+
// because pages are compared at different level, so we compare only their index.
1417+
// However only if both page dictionaries are not in the document's page trees, we continue to comparing them as normal dictionaries.
1418+
if (cmpPagesRef.contains(cmpRefKey) || outPagesRef.contains(outRefKey)) {
1419+
if (cmpPagesRef.contains(cmpRefKey) && cmpPagesRef.indexOf(cmpRefKey) == outPagesRef.indexOf(outRefKey)) {
1420+
return true;
1421+
}
1422+
if (compareResult != null && currentPath != null)
1423+
compareResult.addError(currentPath, MessageFormatUtil.format("The dictionaries refer to different pages. Expected page number: {0}. Found: {1}",
1424+
cmpPagesRef.indexOf(cmpRefKey) + 1, outPagesRef.indexOf(outRefKey) + 1));
1425+
return false;
1426+
}
14201427
}
14211428

14221429
if (cmpDirectObj.isDictionary()) {

0 commit comments

Comments
 (0)